Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFile create file in new directory
Forum Updated to NodeBB v4.3 + New Features

QFile create file in new directory

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 18.4k 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 Extensions
        • Unsolved