问题描述
我是一个Qt初学者,只是陷入了这个问题。我正在寻找一个文件SomePath / NewDirectoryA / NewFile.kml(NewFile.kml将是唯一的文件在NewDirectoryA,有这个目录只是为了维护项目中的语义)。但问题是我必须创建文件的目录本身。我用QFile与文件名称SomePath / NewDirectoryA / NewFile.kml尝试,但它没有奏效。请给我一个方法,我可以在一个新的目录(NewDirectorA)在给定的位置(SomePath)创建一个新的文件(NewFile.kml)。
Qt的文件创建警告
$ b
和
I am a Qt beginner and just got stuck with the problem. I am looking for a file SomePath/NewDirectoryA/NewFile.kml ( NewFile.kml will be the only file in NewDirectoryA, having this directory just to maintain semantics in the project ).
If SomePath/NewDirectoryA/NewFile.kml exists then I will use it in my code and If it doesn't exist then I have to create it. If this File doesn't exist then this directory also doesn't exist in SomePath. So If only I have to create a file I can use QFile and open it in ReadWrite or WriteOnly mode.
But the problem is I have to create the file with the directory itself. I tried with QFile with file name SomePath/NewDirectoryA/NewFile.kml but it didn't worked. Please suggest me a way in which I can create a new file( NewFile.kml ) in a new directory( NewDirectorA ) at a given location( SomePath ).
Qt's caveat for file creation
Directories are created with
and
这篇关于如何在Qt中创建一个新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!