Unsolved App Icon notification behaviour with respect to focus-in and focus-out of the application
-
HI,
I have a single window application.Goal- I want the user to be notified some events when the user is not using this application but the user has the application opened in the background.In short if the user has opened the application and moved away to some other application then the setBadgeLabelText will be called.
Implementation-
I have to figure out when the user has left the application. When this event has happened only then I would call setBadgeLabelText.
When the user comes back to the application again I need to know that as well since at that time I would delete the notifications created by setBadgeLabelText.Questions-
1.How do I know when the user has left the application and when the user has come back to the application? What are the events ?
2. Lets say if the user has minimized the application window and the window is not focused bt the window is showing on the screen, but he is busy working on some other application, say the browser -in such a situation I donot want the user to be notified. Is there a event which fires only when the user doesnt see the window on the screen at all? -
Hi,
You'll likely be interested by QGuiApplication:: applicationStateChanged and the Qt::ApplicationState enumeration.
-
@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)