-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
4.6.2
-
None
On Mac if you hide a widget inside its closeEvent it is not possible to ignore the close event generated by Cmd + Q or Quit from the menu.
It is always possible to ignore when the event is generated by clicking on the red close button.
#include <QtGui> class MyWidget: public QMainWindow { Q_OBJECT public: MyWidget(QWidget *parent = 0); protected: void closeEvent(QCloseEvent* event) { qDebug() << "MainAppWindow::closeEvent"; if (allowClose) { event->accept(); }else{ // REMOVE COMMENT BELOW AND TRY AGAIN TO SEE ISSUE. // setVisible(false); event->ignore(); // try to close again in 2 seconds. QTimer::singleShot(2000, this, SLOT(close())); } }; private slots: void doSomething(); private: QHBoxLayout *layout; QPushButton *button; bool allowClose; }; MyWidget::MyWidget(QWidget *parent) : QMainWindow(parent) { allowClose = false; setWindowTitle("Support Tester"); layout = new QHBoxLayout; button = new QPushButton ("Do Something"); button->setText(QString("The value of allow close is %1").arg(allowClose)); layout->addWidget(button); QWidget *w = new QWidget; w->setLayout(layout); setCentralWidget(w); QObject::connect(button, SIGNAL(clicked()), this, SLOT(doSomething())); } void MyWidget::doSomething() { qDebug("something clicked"); allowClose = !allowClose; button->setText(QString("The value of allow close is %1").arg(allowClose)); } //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(); myWin->show(); return app.exec(); }