QFile create file in new directory
Solved
General and Desktop
-
wrote on 8 Jan 2016, 21:46 last edited by
So I would like to create and save my file into /home/user/Folder. However, if I want to share this code with others then they would have change the user name. Is there any way to make the path be generic so that the file can be saved into their /home/user/ directory without changing the path name? Something like ~/.Folder??
The following code works specifically for me but not for others.
QString path ="/home/myusername/Folder/"; QDir dir; QFile file(path + "file"); if(!dir.exists(path)) { dir.mkpath(path); qDebug()<<"directory now exists"; if ( file.open(QIODevice::ReadWrite) ) { qDebug()<<"file now exists"; } }
-
wrote on 8 Jan 2016, 22:13 last edited by
See QStandardPaths::HomeLocation or QDir::homePath().
-
See QStandardPaths::HomeLocation or QDir::homePath().
wrote on 8 Jan 2016, 23:05 last edited by@mchinand Yes!!! Thank you!
2/3