Can't create a .txt file in specified directory or mkdir()
-
wrote on 17 Jul 2017, 07:06 last edited by MartinChan
I want to create a main.txt file in "data" sub-directory under current working directory and mkdir() can't work.Here is my code.
QString currentWorkingPath=QCoreApplication::applicationFilePath(); QDir dir(currentWorkingPath); qDebug()<<dir.currentPath();//It output the correct path until here if(dir.mkdir("data")) qDebug()<<"MAKE THE DIR";//It can't mkdir() here. QFile mainFile(QString(currentWorkingPath+"/data/main.txt"));//It can't create new sub-dir or txt file either. if (mainFile.open(QIODevice::WriteOnly|QIODevice::Text)){ } mainFile.close();
Can someone give me some advice?I can only create txt in output home directory now.
-
Hi,
Ensure you are not trying to write in a read-only folder. On most OS, the path where an application is installed is not writable by users partly because I could wreak havoc on the device/machine. The QStandardPaths class allows to retrieve usable writable paths for your application to write into depending on the type of data you want to generate.
-
Hi,
Ensure you are not trying to write in a read-only folder. On most OS, the path where an application is installed is not writable by users partly because I could wreak havoc on the device/machine. The QStandardPaths class allows to retrieve usable writable paths for your application to write into depending on the type of data you want to generate.
wrote on 17 Jul 2017, 09:37 last edited by@SGaist Thx and I can use QStandardPath to get a writable path.
1/3