qt creator version 5.3: quitting whole application if one mainwindow is closed

320 Views Asked by At

I am trying to use the QCloseEvent to close all my dialogs and quit the application when the main window closes. I have read the documentation and looked at many examples and this is what I've come up with so far:

In my .h file:

protected:

void mainwindow::closeEvent(QCloseEvent * );

In my mainwindow.cpp file:

class QCloseEvent;
void mainwindow::closeEvent(QCloseEvent *event)
{
    event->accept();

    if (event->isAccepted())
    {
        QApplication::quit();
    }

}

when I run this code I get the following errors: mainwindow::closeEvent' : local function definitions are illegal mainwindow.cpp(13): this line contains a '{' which has not yet been matched

1

There are 1 best solutions below

4
Nejat On

There is a problem with function declaration in your .h file :

void mainwindow::closeEvent(QCloseEvent * );

It should be :

void closeEvent(QCloseEvent * );

Also include QCloseEvent instead of class QCloseEvent;.