Results 1 to 10 of 10

Thread: How do show in a QFileDialog all files except the executable files?

  1. #1
    Join Date
    Apr 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default How do show in a QFileDialog all files except the executable files?

    The only way I can think of is to make a list, but this way I have to anticipate all possible types of files, that is not possible.
    Qt Code:
    1. QFileDialog dialog(this);
    2. dialog.setFileMode(QFileDialog::ExistingFile);
    3. dialog.setNameFilter(tr("All files except .exe (*.png *.xpm *.jpg *.pdf *.gif ............infinite extensions..........)"));
    To copy to clipboard, switch view to plain text mode 

    Anyone has a better idea?
    Thank you very much.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do show in a QFileDialog all files except the executable files?

    Just use QDialog::setFilter not QDialog::setNameFilter

  3. #3
    Join Date
    Apr 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do show in a QFileDialog all files except the executable files?

    Sorry, I tried as you say, but does not work.

    Qt Code:
    1. #include <QApplication>
    2. #include <QFileDialog>
    3.  
    4. int main( int argc, char **argv ) {
    5.  
    6. QApplication app( argc, argv );
    7. QFileDialog dialog(0);
    8. dialog.setFileMode(QFileDialog::ExistingFile);
    9. dialog.setFilter(QDir::Files); //<--------------------------All files except executable files.???
    10. dialog.exec();
    11. return 0;
    12. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Last edited by bhodi78; 27th April 2010 at 16:21.

  4. #4
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: How do show in a QFileDialog all files except the executable files?

    dialog.setFilter(QDir::Files); //<--------------------------All files except executable files.???
    Very interesting problem. There is a QDir::Readable, a QDir::Writable, and a QDir::Executable. All three must be combined with QDir::Files. If QDir::Files shows all files, why add one of the three? To show all files + readable, writable, and executable files? Would only make sense if QDir::Files alone shows nothing. Or QDir::Files shows all, but the writable, readable, executable flags actually subtract files with those permissions. Looks like a minor documentation bug to me.
    Try: dialog.setFilter(QDir::Files|QDir::Readable|QDir:: Writable);
    or: dialog.setFilter(QDir::Files|QDir::executable);
    Just as an experiment. What is the result?

  5. #5
    Join Date
    Apr 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do show in a QFileDialog all files except the executable files?

    I tried
    dialog.setFilter (QDir:: Files | QDir:: Readable | QDir:: Writable);
    and so I see all the files except "exe" but I do not see the folders.
    Same problem for these two cases:
    dialog.setFilter (QDir:: Dirs | QDir:: Files | QDir:: Readable | QDir:: Writable) and
    dialog.setFilter (QDir:: Dirs | QDir:: Files | QDir:: Readable | QDir:: Writable | QDir:: Modified);

    Instead
    dialog.setFilter (QDir:: Files | QDir:: Executable);
    I only see the files. "exe" without all the other folders and files.

  6. #6
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: How do show in a QFileDialog all files except the executable files?

    So,
    dialog.setFilter (QDir:: Files | QDir:: Readable | QDir:: Writable);
    goes into the right direction.

    I don't know the solution, but I would now try:
    dialog.setFilter (QDir::AllDirs| QDir:: Readable | QDir:: Writable)

  7. #7
    Join Date
    Apr 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do show in a QFileDialog all files except the executable files?

    thanks for your help, but unfortunately it does not work that way. :-(

  8. #8
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: How do show in a QFileDialog all files except the executable files?

    Looks like a Qt bug to me. According to the assistant:
    QDir::AllDirs 0x400 List all directories; i.e. don't apply the filters to directory names.
    But the executables are filtered. And of course, folders are executable, else it would be impossible to enter them.
    At least under Linux.

  9. #9
    Join Date
    Apr 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do show in a QFileDialog all files except the executable files?

    Amazing we found a bug in qt ..... and now how do I solve the problem? what do you do in these situations?

  10. #10
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: How do show in a QFileDialog all files except the executable files?

    Quote Originally Posted by bhodi78 View Post
    Amazing we found a bug in qt ..... and now how do I solve the problem? what do you do in these situations?
    If it is really a bug... let's wait for the answer from the Trolls. We simply might have overlooked something. I filed a bug report.

Similar Threads

  1. To identify executable and other files in QT Application
    By augusbas in forum Qt Programming
    Replies: 3
    Last Post: 8th March 2010, 18:29
  2. Replies: 1
    Last Post: 30th October 2009, 03:42
  3. Replies: 12
    Last Post: 17th June 2009, 05:34
  4. Select multiple files from QFileDialog
    By jiveaxe in forum Qt Programming
    Replies: 6
    Last Post: 16th February 2009, 14:57
  5. QFileDialog hidden files
    By blukske in forum Qt Programming
    Replies: 3
    Last Post: 8th March 2007, 02:11

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.