Unsolved App Icon notification behaviour with respect to focus-in and focus-out of the application
-
@SGaist said in App Icon notification behaviour with respect to focus-in and focus-out of the application:
QGuiApplication:: applicationStateChanged
I am using QApplication, is it anyways possible with QApplication?
-
@gully
Hi
Since its
class Q_WIDGETS_EXPORT QApplication : public QGuiApplicationit should be possible ?
-
QApplication a(argc, argv); livewindow window; QApplication::connect(a, SIGNAL(applicationStateChanged(Qt::ApplicationState state)),window, SLOT(appstate(Qt::ApplicationState state)));
This is what I am doing..but getting an error..What would be the right way to do this?
-
@gully
Well, first of all, always show the actual error :)
in this case i think you needQObject::connect(&a, SIGNAL(applicationStateChanged(Qt::ApplicationState
state)),window, SLOT(appstate(Qt::ApplicationStatestate))); // dont include varname, only type -
@mrjj said in App Icon notification behaviour with respect to focus-in and focus-out of the application:
QObject::connect(&a, SIGNAL(applicationStateChanged(Qt::ApplicationState state)),window, SLOT(appstate(Qt::ApplicationState state)));
Now I am getting
error: no matching function for call to 'connect'
QObject::connect(&a, SIGNAL(applicationStateChanged(Qt::ApplicationState)),window, SLOT(appstate(Qt::ApplicationState)));
^~~~~~~~~~~~~~~~ -
Hmm
let me try
is window , a normal MainWindow in main, or where do you do it ? -
Hi
Tried.int main(int argc, char* argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); qDebug() << "works" << QObject::connect(&a, SIGNAL(applicationStateChanged(Qt::ApplicationState)), &w, SLOT(appstate(Qt::ApplicationState))); return a.exec(); }
return true so seems to like it.
in mainwindow , i have
public slots: void appstate(Qt::ApplicationState) {}
update:
i also put qDebug() in appstate
and it fires/works. -
Thanx a lot..yeeah its working now... But I wonder what I was doing wrong?
-
@gully
my best guess is you forgot & if the objects you connect is not pointers.
Like MainWindow in main.cpp.
so it was &window but not sure if pointer or not. -
Thanks a ton for pointing it out.Yes indeed that is what I missed out.
-
@gully
Just as a note.
Unless in main.cpp , if you need to use & for a connect, check that the object wont run out of
scope and be deleted when function ends.
In main.cpp, the "return a.exec();" blocks and it wont run out of scope.
But in other places, having to use & should raise a flag in head so check the objects in the
connect. (should be pointers in most places)