Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-78557

QFileDialog::getOpenFileName() using native dialog on Ubuntu/Gtk swallows filter extension

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.11.1
    • None
    • Ubuntu 18.04.3 LTS 64-bit
      Gnome 3.28.2
      Qt 5.11.1
    • Linux/X11

    Description

      When selecting a file to open or save, we can pass a filter string to the static functions mentioned in the subject line. The expected behavior is to retain the extension/s in the human-readable part of the filter name, i.e. the user should be able to see what the extension is, for example "Text files (*.txt)" and not just "Text files".

      However, the extension is hidden from the user on Linux Ubuntu using the default file navigator.

      Here is a small illustration:

      #include <QMainWindow>
      #include <QApplication>
      #include <QPushButton>
      #include <QtCore>
      #include <QFileDialog>
      #include <QMessageBox>
      
      int main(int argc, char *argv[])
      {
        QApplication a(argc, argv);
        QMainWindow w;
        QPushButton b;
        b.setText("Bye!");
        w.setCentralWidget(&b);
        w.connect(&b, &QPushButton::clicked, &w, &QMainWindow::close);
      
        QString fn = QFileDialog::getOpenFileName(
              &w,
              "Testing the native dialog",
              QString(),
              "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)");
        if (!fn.isEmpty()) {
          QString msg = "You chose the file:\n";
          QMessageBox::information(&w,"File Selected",msg.append(fn));
        }
        fn = QFileDialog::getOpenFileName(
               &w,
               "Testing the Qt (non-native) dialog",
              QString(),
              "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)",
              nullptr, QFileDialog::DontUseNativeDialog);
        if (!fn.isEmpty()) {
          QString msg = "You chose the file:\n";
          QMessageBox::information(&w,"File Selected",msg.append(fn));
        }
      
        w.show();
        return a.exec();
      }
      
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            robert_hairgrove Bob Hairgrove
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes