Wolf
Wolf

Reputation: 119

Qt/C++ - Closing two widgets when one is closed

I have a main window which creates two widgets: the "main window" with menus and the main application and a widget that makes available various settings in its own window, disconnected from the main application.

Is there an event in Qt such that I can force the settings widget to close if i close/hide/X out the main application's window?

Upvotes: 1

Views: 1567

Answers (2)

Fabio
Fabio

Reputation: 2602

You can:

1- make the settings widget a child of the main window

2- use an event filter to detect the close event of the main window (see QObject::installEventFilter() and QCloseEvent)

3- Override closeEvent int the main window

Upvotes: 4

ratchet freak
ratchet freak

Reputation: 48196

The main window has a closeEvent function you can override to close the other window:

void MainWindow::closeEvent(QCloseEvent *event)
{
    otherWindow->close();
    QMainWindow::closeEvent(event);
}

Upvotes: 3

Related Questions