Results 1 to 6 of 6

Thread: QFileDialog selecting file or directory

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QFileDialog selecting file or directory

    Hi,

    I want a QFileDialog that could select "mp3" extension files and also a directory could be selected(note that I only want one selection, so you can select one MP3 file or a directory).
    I've inserted "Music (*.mp3)" as filter but don't know how to let it select dirs.

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog selecting file or directory

    Hi,

    Have solved it just calling "setFileMode(QFileDialog:irectory)" to the dialog.
    The problem is that now the dialog is different that if I use the static function "QFileDialog::getOpenFileName". It is not look native and it is not translated.

    Thanks,
    Òscar Llarch i Galán

  3. #3
    Join Date
    Jun 2008
    Posts
    35
    Thanks
    5
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QFileDialog selecting file or directory

    I hope that 'll be useful .
    That's Code I use to filter JPG & set the path @ a Label :

    Qt Code:
    1. QFileDialog::Options options;
    2.  
    3. options |= QFileDialog::DontUseNativeDialog;
    4. QString selectedFilter;
    5.  
    6. QString fileName = QFileDialog::getOpenFileName(this,
    7. tr("Open"),
    8. formTwo.lblSelectedFilePath->text(),
    9. tr("JPEG (*.JPG)"),
    10. &selectedFilter,
    11. options);
    12.  
    13.  
    14. if (!fileName.isEmpty())
    15. formTwo.lblSelectedFilePath->setText(fileName);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog selecting file or directory

    Hi,

    I'm having the problem yet. The dialog only let me selec directories now.

    Thanks,
    Òscar Llarch i Galán

  5. #5
    Join Date
    Dec 2018
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QFileDialog selecting file or directory

    This fails for me. I can only select files. No way to select the directory without opening it up. The question was how to select a file, or a directory. This only selects files.
    -- Doug Royer (https://DougRoyer.US)

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,103
    Thanks
    290
    Thanked 844 Times in 831 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QFileDialog selecting file or directory

    If you are using the QFileDialog static methods, then you call QFileDialog::getExistingDirectory() to select directories only and QFileDialog::getOpenFileName() for files only. If you are using the non-static method (ie. via QFileDialog::exec()) than you set the option QFileDialog::ShowDirsOnly and use QFileDialog::Directory file mode.

    The original post is 13 years old, during Qt 3 or Qt 4 days. Qt is three major revisions past that now.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 13th June 2007, 15:37
  2. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  3. errors while installing Qt4.2 in Linux
    By nimmyj in forum Installation and Deployment
    Replies: 11
    Last Post: 13th December 2006, 11:58
  4. create file in another directory
    By raphaelf in forum Qt Programming
    Replies: 3
    Last Post: 16th February 2006, 10:04
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

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.