Results 1 to 3 of 3

Thread: QDir::mkpath

  1. #1
    Join Date
    Apr 2008
    Location
    Pittsburgh,PA,USA
    Posts
    48
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDir::mkpath

    I am trying to figure out the intend usage of QDir::mkpath

    On Qt 4.3 on windows XP

    Qt Code:
    1. Qdir dir("John");
    2.  
    3. dir.mkpath("Kathy");
    To copy to clipboard, switch view to plain text mode 

    The result is John/Kathy which is not what I expected especially because my intended usage was as follows.

    Qt Code:
    1. QDir dir("John");
    2.  
    3. if (!dir.exists()) {
    4. dir.mkpath("John");
    5. }
    To copy to clipboard, switch view to plain text mode 

    However the result is

    John/John
    is created.

    I tried
    Qt Code:
    1. QDir dir("John");
    2.  
    3. if (!dir.exists()) {
    4. dir.mkpath(".");
    5. }
    To copy to clipboard, switch view to plain text mode 

    and got what I wanted (created just John in the current folder) however I am unsure that this will work on all platforms.

    Also if you

    Qt Code:
    1. QDir dir("John");
    2.  
    3. if (!dir.exists()) {
    4. dir.mkpath("");
    5. }
    To copy to clipboard, switch view to plain text mode 

    it exits with false because the path can not be empty.
    John

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QDir::mkpath

    I think what you want to do is just instantiate an empty QDir, which will default to the program directory, then you can use mkpath to make a path wherever you want and it will create the proper directory structure for you, if it doesn't exist already:

    Qt Code:
    1. QDir myDir();
    2. if(!myDir.exists("John"))
    3. {
    4. myDir.mkpath("John/Kathy/Ben/George/Ringo");
    5. }
    To copy to clipboard, switch view to plain text mode 

    Or maybe that's not what you intend.

  3. #3
    Join Date
    Apr 2008
    Location
    Pittsburgh,PA,USA
    Posts
    48
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDir::mkpath



    Thanks. Sounds reasonable.
    John

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.