Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

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

like image 855
Manu53 Avatar asked Feb 04 '23 12:02

Manu53


1 Answers

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();
}
like image 160
aatwo Avatar answered Feb 12 '23 19:02

aatwo