Results 1 to 4 of 4

Thread: How do I create a directory ?

  1. #1
    Join Date
    Jul 2011
    Location
    Paris
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How do I create a directory ?

    Hello,

    I have an application in which I need to save files into a directory. First I have a QDialog in which I fill in some information through combo-boxes and Line edits and when hitting the OK button I want to create a directory with a specified name in the home directory.

    So if I set the name to "myDirectory" I want to be able to see (in Windows explorer for example) a folder created with the name "myDirectory" to later save files into that folder. The whole path would be C:/Users/home/myDirectory

    I tried doing something like this:


    Qt Code:
    1. void myDialog::createDirectory()
    2. {
    3. QString filePath = QDir::homePath() + "/" + m_Name;
    4.  
    5. QDir dir;
    6. dir.mkdir(m_Name);
    7. }
    To copy to clipboard, switch view to plain text mode 

    What am I missing to make this work??

    Thank you.

  2. #2
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How do I create a directory ?


  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I create a directory ?

    Quote Originally Posted by Sergex View Post
    Hello,

    I have an application in which I need to save files into a directory. First I have a QDialog in which I fill in some information through combo-boxes and Line edits and when hitting the OK button I want to create a directory with a specified name in the home directory.

    So if I set the name to "myDirectory" I want to be able to see (in Windows explorer for example) a folder created with the name "myDirectory" to later save files into that folder. The whole path would be C:/Users/home/myDirectory

    I tried doing something like this:


    Qt Code:
    1. void myDialog::createDirectory()
    2. {
    3. QString filePath = QDir::homePath() + "/" + m_Name;
    4.  
    5. QDir dir;
    6. dir.mkdir(m_Name);
    7. }
    To copy to clipboard, switch view to plain text mode 

    What am I missing to make this work??

    Thank you.
    Judging from the manual (http://doc.qt.io/qt-4.8/QDir.html#mkdir), "you're doing it wrong".
    Qt Code:
    1. void myDialog::createDirectory()
    2. {
    3. QString filePath = QDir::homePath();
    4.  
    5. QDir dir(filePath);
    6. dir.mkdir(m_Name);
    7. }
    To copy to clipboard, switch view to plain text mode 
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I create a directory ?

    Quote Originally Posted by amleto View Post
    Qt Code:
    1. void myDialog::createDirectory()
    2. {
    3. QString filePath = QDir::homePath();
    4.  
    5. QDir dir(filePath);
    6. dir.mkdir(m_Name);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Or just
    Qt Code:
    1. QDir::home().mkdir(m_Name);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. How to create a directory with hidden attribute
    By sanjayshelke in forum Qt Programming
    Replies: 6
    Last Post: 8th November 2012, 13:09
  2. Create a private directory under user
    By thru in forum Qt Programming
    Replies: 4
    Last Post: 22nd March 2011, 12:44
  3. how to create shortcut to a directory
    By kamlmish in forum Newbie
    Replies: 1
    Last Post: 28th January 2011, 05:18
  4. How to create a symlink to a directory?
    By ucomesdag in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2007, 19:01
  5. create file in another directory
    By raphaelf in forum Qt Programming
    Replies: 3
    Last Post: 16th February 2006, 10:04

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.