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

Cannot close window after hiding and showing again

    XMLWordPrintable

Details

    Description

      The following code shows a window, hides it, shows it again, then tries to close it.

      #include <QApplication>
      #include <QTimer>
      #include <QWindow>
      #include <QDebug>
      #include <QMainWindow>
      #include <QCloseEvent>
      
      class Window : public QMainWindow
      {
      public:
          void closeEvent(QCloseEvent *e) {
              qWarning() << "close event";
              hide();
              e->ignore();
          }
      };
      
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
          auto window = new Window;
      
          window->show();
          QTimer::singleShot(5000, [window]{
              qWarning() << "hide";
              window->hide(); 
              QTimer::singleShot(5000, [window]{
                  qWarning() << "show";
                  window->windowHandle()->show();
                  QTimer::singleShot(5000, [window] {
                      qWarning() << "close";
                      window->close();
                  });
              });
          });
          return app.exec();
      }
       

      Despite calling window->close() the window stays open. The same happens when closing the window via the close button. Expected is that the window is hidden but the application does not terminate.

      The problem does not occur when replacing the

      window->windowHandle()->show()
      

      with

      window->show()
      

      Tested on Qt 6.6 and 6.7 beta, on X11 and Wayland.

      The issue is not present in Qt 5.15

      The shown code is a condensed version of what happens in various KDE applications when closing to and restoring from system tray. See https://bugs.kde.org/show_bug.cgi?id=478734

       

      Attachments

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

        Activity

          People

            vestbo Tor Arne Vestbø
            nicolasfella Nicolas Fella
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes