Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFile create file in new directory
Qt 6.12 LTS is out! See what's new in the release blog

QFile create file in new directory

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 19.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marlenet15
    wrote on last edited by
    #1

    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";
        }
    }
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by
      #2

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

      M 1 Reply Last reply
      0
      • M mchinand

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

        M Offline
        M Offline
        marlenet15
        wrote on last edited by
        #3

        @mchinand Yes!!! Thank you!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved