QT QFileDialog doesn't list all available files in target directory

74 Views Asked by At

When calling the static function QFileDialog::getOpenFileNames() from a dialog in my application, I get only one file extension defined by the file filters (rather than both), and only a single file from the target directory (rather all the files available).

Here is getOpenFileNames() being called from from main():

#include <QApplication>
#include <QFileDialog>
#include <QString>

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);

  QStringList filenames = QFileDialog::getOpenFileNames(
            NULL,
            "Select data file",
            "/home/gss/Data/",
            "Data Files (*.raw *.RAW)" );
}

Browsing to the desired directory with the dialog results in all the .raw and .RAW files being shown.

QT Creator 5.0.2 CentOS 8

1

There are 1 best solutions below

1
Andrey Shmelev On

doc.qt.io

says:

QStringList files = QFileDialog::getOpenFileNames(
                        this,
                        "Select one or more files to open",
                        "/home",
                        "Images (*.png *.xpm *.jpg)");

please, try

QStringList filenames = QFileDialog::getOpenFileNames(
          this,
          "Select data file",
          "/home/gss/Data",
          "Data Files (*.raw *.RAW)" );