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

Quit on cocoa still possible, even though the Quit action in the application menu is disabled.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 4.6.2, 4.6.3, 4.7.0
    • GUI: Window management
    • None
    • Snow Leopard cocoa build.
    • macOS

      When the quit action is disabled in a Qt cocoa application it is still possible to quit the Qt application by right clicking on the dock icon, or closing the window when app.setQuitOnLastWindowClosed is not set.

      #include <QtGui>
      
      class MyWidget: public QWidget
      {
          Q_OBJECT
          
      public:
          MyWidget(QWidget *parent = 0);
          
      private slots: 
          void doSomething();
          void quitActionCalled();
      
      private:
          QHBoxLayout *layout;
          QPushButton *button;
          QMenuBar *menuBar;
          QAction *quitAction;
      };        
      
      MyWidget::MyWidget(QWidget *parent) : QWidget(parent) 
      {
          setWindowTitle("Support Tester");
          layout = new QHBoxLayout;
          button = new QPushButton ("toggle quit state");
          layout->addWidget(button);
          
          setLayout(layout);
          
          menuBar = new QMenuBar(0);
          QMenu *menu = menuBar->addMenu("testMenu");
          quitAction = menu->addAction("Quit",this,SLOT(quitActionCalled()));
      
      
      
          QObject::connect(button, SIGNAL(clicked()),
                           this, SLOT(doSomething()));
      }
      
      void MyWidget::quitActionCalled()
      {
          qDebug("quit");
      }
      
      void MyWidget::doSomething()
      {
          if (quitAction->isEnabled())
          {
              quitAction->setEnabled(false);
          }
          else
          {
              quitAction->setEnabled(true);
          }
          qDebug("quit state toggled");
      }
      
      //This moc include is to get everything in a single file - for quick testing only
      #include "main.moc"
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          MyWidget *myWin = new MyWidget();
      //    app.setQuitOnLastWindowClosed(false);
          myWin->show();
      
          return app.exec();
      
      }
      
      

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

            Unassigned Unassigned
            dettman Dean Dettman (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes