how to run myfunction() when I close a window
- 
Hi everyone, 
 I need to run myfunction() when I close the window named mywindow programmatically opened inside the FullScreen class.h namespace Ui { class FullScreen; } class FullScreen : public QWidget { Q_OBJECT public: explicit FullScreen(QWidget *parent = nullptr); ~FullScreen(); private: Ui::FullScreen *ui; QWindow *mywindow; private slots: void on_button_released(); void myfunction(); };.cpp void FullScreen::on_button_released() { WId wid = (WId)FindWindow(L"ScreenClass", nullptr); mywindow = QWindow::fromWinId(wid); // I tried like this, but it doesn't work QObject::connect(mywindow, &QWindow::windowStateChanged, this, [this](Qt::WindowState state){ if (state == Qt::WindowNoState && mywindow->isVisible() == false) { myfunction(); } }); } void FullScreen::myfunction() { my code; }Does anyone have a different solution? 
 Thank you in advance
 blackout69
- 
Hi everyone, 
 I need to run myfunction() when I close the window named mywindow programmatically opened inside the FullScreen class.h namespace Ui { class FullScreen; } class FullScreen : public QWidget { Q_OBJECT public: explicit FullScreen(QWidget *parent = nullptr); ~FullScreen(); private: Ui::FullScreen *ui; QWindow *mywindow; private slots: void on_button_released(); void myfunction(); };.cpp void FullScreen::on_button_released() { WId wid = (WId)FindWindow(L"ScreenClass", nullptr); mywindow = QWindow::fromWinId(wid); // I tried like this, but it doesn't work QObject::connect(mywindow, &QWindow::windowStateChanged, this, [this](Qt::WindowState state){ if (state == Qt::WindowNoState && mywindow->isVisible() == false) { myfunction(); } }); } void FullScreen::myfunction() { my code; }Does anyone have a different solution? 
 Thank you in advance
 blackout69@blackout69 
 To run code on closing aQWidget, either subclass and overridecloseEvent()or detect it viainstallEventFilter()(avoids subclassing, but here you are already subclassing).
- 
@blackout69 
 To run code on closing aQWidget, either subclass and overridecloseEvent()or detect it viainstallEventFilter()(avoids subclassing, but here you are already subclassing).@JonB Since the OP's window is got by QWindow::fromWinId(probably from a non-Qt program's window handle), I doubt he could get any information according to the doc of the function:Note: The resulting QWindow should not be used to manipulate the underlying native window (besides re-parenting), or to observe state changes of the native window. Any support for these kind of operations is incidental, highly platform dependent and untested. 
- 
@JonB Since the OP's window is got by QWindow::fromWinId(probably from a non-Qt program's window handle), I doubt he could get any information according to the doc of the function:Note: The resulting QWindow should not be used to manipulate the underlying native window (besides re-parenting), or to observe state changes of the native window. Any support for these kind of operations is incidental, highly platform dependent and untested. 
 

