Manu53
Manu53

Reputation: 101

What is the signal emitted when we close a Window in qt

I have my MainWindow that open a second Window.

When I click on a button in my second window, a thread is launched and I want my thread to end when I quit my second window.

What is the signal emitted when my SecondWindow is closed ?

Thank you for your futures answers

Upvotes: 8

Views: 14274

Answers (1)

aatwo
aatwo

Reputation: 1008

There is no signal emitted when widgets (including QMainWindows) are closed. If a widget is set to be deleted when it is closed then you could use the following QObject signal to detect when the widget is about to be destroyed...

void    destroyed(QObject *obj = Q_NULLPTR)

However this will only work if your window has the Qt::WA_DeleteOnClose flag enabled (it is not enabled by default).

Alternatively and probably more preferably you can implement the standard widget close event and emit your own signal to indicate that the window was closed:

void MainWindow::closeEvent( QCloseEvent* event )
{
    emit MySignalToIndicateThatTheWindowIsClosing();
    event->accept();
}

Upvotes: 14

Related Questions