QFile create file in new directory

  • 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");
        qDebug()<<"directory now exists";
        if ( file.open(QIODevice::ReadWrite) )
            qDebug()<<"file now exists";

  • See QStandardPaths::HomeLocation or QDir::homePath().

  • @mchinand Yes!!! Thank you!

Log in to reply