Results 1 to 9 of 9

Thread: How to select both files and folders using QFileDialog.

  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default How to select both files and folders using QFileDialog.

    Hi all,

    I need a "select folders + files" dialog.

    In which using same QFileDialog i can select either file or folder.

    Regards
    Merry
    Always Believe in Urself
    Merry

  2. #2
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to select both files and folders using QFileDialog.


  3. #3
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to select both files and folders using QFileDialog.

    Yeah, I tried but no use i am able to select files only but nt directories.
    Always Believe in Urself
    Merry

  4. #4
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to select both files and folders using QFileDialog.

    post your code snippet having file dlg operation.

  5. #5
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to select both files and folders using QFileDialog.

    Here is the code:

    Qt Code:
    1. QFileDialog dialog(this);
    2. dialog.setFileMode(QFileDialog::DirectoryOnly);
    3. QString strFileName = dialog.getOpenFileName(this,tr("Select File"), "", tr("All Files (*.*)"));
    To copy to clipboard, switch view to plain text mode 
    Always Believe in Urself
    Merry

  6. #6
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to select both files and folders using QFileDialog.

    Quote Originally Posted by merry View Post
    Here is the code:

    Qt Code:
    1. getOpenFileName(this,tr("Select File"), "", tr("All Files (*.*)"));
    To copy to clipboard, switch view to plain text mode 
    getOpenFileName(...) is a static method and has its own instance. The dialog instance created by you with flags won't affect this instance.

    why can't you use getExistingDirectory ?

  7. #7
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to select both files and folders using QFileDialog.

    Thanks for the reply.

    why can't you use getExistingDirectory ?
    using this i am able to select dirs ony not files. I want to make a dialog in which i can able to select both files and dirs .
    Always Believe in Urself
    Merry

  8. #8
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to select both files and folders using QFileDialog.

    you can try this,

    Qt Code:
    1. QFileDialog* dlg = new QFileDialog(NULL);
    2. dlg->setFileMode(QFileDialog::Directory);
    3. int nMode = dlg->exec();
    4. QStringList strlist = dlg->selectedFiles();
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to select both files and folders using QFileDialog.

    I also have the same problems, and after searching and trying for some times, I found this solution works. You could try.

    http://www.qtcentre.org/threads/3422...108#post220108

Similar Threads

  1. Replies: 0
    Last Post: 11th February 2011, 05:48
  2. Replies: 6
    Last Post: 13th June 2010, 21:09
  3. Qt select folders and files dialog.
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 13th July 2009, 09:53
  4. Select multiple files from QFileDialog
    By jiveaxe in forum Qt Programming
    Replies: 6
    Last Post: 16th February 2009, 15:57
  5. Replies: 1
    Last Post: 5th October 2007, 10:51

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.