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
AFAIK it is not possible to create the file and the directory directly with
QFile
. You have to first create the directory (QDir::mkpath
will create the full path) and then the file (QFile::open
).