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

Calling a QFileDialog static function or QFileDialog::exec() with native dialogs temporarily sets qApp::activeWindow to NULL

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 5.2.1
    • GUI: Window management
    • None
    • Windows7, Visual Studio 2010

    Description

      I noticed that calling a static member of QFileDialog unsets the active window.
      Static members of QMessageBox apparently do not have this issue.

      Workaround: calling qApp->processEvents(); fixes the problem

      Example:

      #include <QApplication>
      #include <QFileDialog>
      #include <QVBoxLayout>
      #include <QPushButton>
      class Dialog : public QDialog
      {
          Q_OBJECT
      public:
          Dialog()
          {
              QVBoxLayout* layout = new QVBoxLayout();
              QPushButton* button = new QPushButton( "Open popup", this );
              layout->addWidget( button );
              connect( button, SIGNAL(clicked()), this, SLOT(openPopup()) );
          }
      
      public slots:
          void openPopup()
          {
              QWidget* widget = qApp->activeWindow();
      
              QFileDialog::getExistingDirectory(
                          widget, // pass widget or NULL: same behaviour
                          "toto",
                          "tata" );
          
              // qApp->processEvents();
      
              QWidget* widget2 = qApp->activeWindow();
              // here widget == this and widget2 == NULL. {color:red}THAT'S THE BUG!{color}
              // If called qApp->processEvents(), widget == widget2 == this
          }
      };
      
      int main( int argc, char* argv[] )
      {
          QApplication app( argc, argv );
          
          Dialog dlg;
          dlg.show();
      
          return app.exec();
      }
      

      Attachments

        For Gerrit Dashboard: QTBUG-38414
        # Subject Branch Project Status CR V

        Activity

          People

            Unassigned Unassigned
            jpo38 Jean Porcherot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes