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

Qt app on Mac deactivates when user closes a modal dialog...

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.7
    • 5.2.1
    • GUI: Window management
    • None
    • OSX 10.8.5, XCode
    • macOS

    Description

      (Although I ran into it with 5.2.1, the problem probably exists in prior 5.x versions as well)

      When user closes a modal dialog, the application should not get an ApplicationStateChange. Yet on Mac, we do - the application would get deactivated then immediately reactivated again.

      Such an unexpected behavior has the potential to throw any code that relies on QGuiApplication::applicationStateChanged() to detect user switching away to another application into a tailspin.

      Attached please find a sample app that repros the problem (file listings below).

      Here are the steps:
      1) launch the sample app
      2) select "Test" from the menu bar, then "Random Dialog...", which just launches a modal generic QDialog
      3) dismiss the dialog by clicking the red 'Close' button
      4) notice that just by closing we get a pair of Qt::ApplicationInactive/Qt::ApplicationActive in the stdout

      MainWindow.cpp
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          QMenuBar* menuBar = new QMenuBar;
          QMenu* testMenu = menuBar->addMenu("Test");
          QAction* act = testMenu->addAction("Random Dialog...");
          connect(act, &QAction::triggered, this, &MainWindow::showRandomDialog);
      
          setMenuBar(menuBar);
      
          connect(qApp, &QGuiApplication::applicationStateChanged, this, &MainWindow::handleApplicationStateChanged);
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      
      void
      MainWindow::handleApplicationStateChanged(Qt::ApplicationState state)
      {
          qDebug("App state changed to %d", (int) state);
      }
      
      void
      MainWindow::showRandomDialog()
      {
          QDialog dlg;
          dlg.exec();
      }
      

      Attachments

        Issue Links

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

          Activity

            People

              srutledg Shawn Rutledge
              bienur Pinyen Chen
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes