How to check if the application has been minimized
-
int main(int argc, char *argv[]) { QApplication application(argc, argv); Renderer w(model ); // This is QWidget w.show(); QObject::connect(&w, &QWindow::windowStateChanged, [&](Qt::WindowState state) { }); // how will i define the QObject::connect return application.exec(); } What would be the parameters for the QObject::connect function ?
-
int main(int argc, char *argv[]) { QApplication application(argc, argv); Renderer w(model ); // This is QWidget w.show(); QObject::connect(&w, &QWindow::windowStateChanged, [&](Qt::WindowState state) { }); // how will i define the QObject::connect return application.exec(); } What would be the parameters for the QObject::connect function ?
@summit said in How to check if the application has been minimized:
What would be the parameters for the QObject::connect function ?
You already have the connect, so what is the question?
Just check state == Qt::WindowMinimized in your lambda... -
@jsulm No this does not connect it gives an error during compile time , no instance of overloaded function matches the argument list.
so i try this
QWindow *wndQT = (QWindow*)w.window(); QObject::connect(wndQT, &QWindow::windowStateChanged , [&](Qt::WindowState state) { qDebug() << "Minimized"; }); This is able to compile but the lambda is never executed.
-
@jsulm No this does not connect it gives an error during compile time , no instance of overloaded function matches the argument list.
so i try this
QWindow *wndQT = (QWindow*)w.window(); QObject::connect(wndQT, &QWindow::windowStateChanged , [&](Qt::WindowState state) { qDebug() << "Minimized"; }); This is able to compile but the lambda is never executed.
-
@summit w.window() returns a QWidget, not QWindow.
TryQObject::connect(QApplication::activeWindow(), &QWindow::windowStateChanged , [&](Qt::WindowState state) { qDebug() << "Minimized"; });
@jsulm This does not compile as QApplication::activeWindow() also returns QWidget*
i have to cast it to compile.
QObject::connect((QWindow*)QApplication::activeWindow(), &QWindow::windowStateChanged , [&](Qt::WindowState state) {
qDebug() << "Minimized";
});But still lambda does not execute.
-
Using QApplication::focusWindow() i was able to get the window.
QObject::connect(QApplication::focusWindow(), &QWindow::windowStateChanged , [&](Qt::WindowState state) {
qDebug() << "Minimized";
}); -
@summit
Just for the record, you do actually need/ought check the value of thestate
parameter to the lambda:if (state == Qt::WindowMinimized) qDebug() << "Minimized";
?