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

QFile create file in new directory

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 18.2k 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 8 Jan 2016, 21:46 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 8 Jan 2016, 22:13 last edited by
      #2

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

      M 1 Reply Last reply 8 Jan 2016, 23:05
      0
      • M mchinand
        8 Jan 2016, 22:13

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

        M Offline
        M Offline
        marlenet15
        wrote on 8 Jan 2016, 23:05 last edited by
        #3

        @mchinand Yes!!! Thank you!

        1 Reply Last reply
        0

        2/3

        8 Jan 2016, 22:13

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved