0

Ok, so why is this code not working??

void Jarvis::closeEvent(QCloseEvent *e)
{
    if (m_doQuit) {
        e->accept();
    } else {
        e->ignore();
        hide();
    }
}

m_doQuit is true, I checked that.

For now I am using

void Jarvis::closeEvent(QCloseEvent *e)
{
    if (m_doQuit) {
        QApplication::quit();
        e->accept();
    } else {
        e->ignore();
        hide();
    }
}

which does work, but IMHO should work even the first one. Why it does not work?

By "doest not work" I mean that application is not closed :/ It just keeps running.

graywolf
  • 7,092
  • 7
  • 53
  • 77

1 Answers1

0

I assume that Jarvis inherits QWidget.

Then you shoud pass the event to the QWidget class like this:

void Jarvis::closeEvent(QCloseEvent *e)
{
    if (m_doQuit) {
        QWidget::closeEvent(e);
    } else {
        e->ignore();
        hide();
    }
}

Simply accepting the event will do nothing. Maybe you could accept the event in the second case, since you are somehow reacting to it. Even though you don't close... but that's for a reason.

HWende
  • 1,705
  • 4
  • 18
  • 30
  • Jarvis inherits QMainWindow.. So I tried putting QMainWindow::closeEvent(e) there, but did not help.. – graywolf Aug 15 '13 at 13:41