[Interest] applicationStateChanged in QML

Bo Thorsen bo at vikingsoft.eu
Fri Aug 15 07:47:33 CEST 2014

Den 15-08-2014 03:28, mark diener skrev:
> Does anybody know how to receive application signals from
> QGuiApplication in Qt Quick 2.0 application?
> I do not want to use a binding
> The signal coming from QGuiApplication ->void *applicationStateChanged
> <http://qt-project.org/doc/qt-5/qguiapplication.html#applicationStateChanged>*(Qt::ApplicationState/state/)
> Inside QML, I want to use a Connections component to get the signal
> triggered in QML
> Or can I only deal with this signal inside of C++?   And then use my own
> global singleton class
> to trigger a signal into QML?
> I have searched high and low.
> Maybe there is a way to use the Qt.application.active property and bind
> it so that it will call
> a javascript function?

Hi Mark,

To use a Connection object, you have to export the source object from 
C++. Something like this:

view.rootObject()->setContextProperty("qGuiApp", &guiApp);

Now you can access the object from QML as you would any item.

Connections {
   target: qGuiApp
   onApplicationStateChanged: {
     console.log("State change", state)

You can export and use any QObject like this.

I usually don't export the Qt objects directly, but instead make some 
kind of backend object that holds the fundamental state of the application.

Bo Thorsen,
Director, Viking Software.

Viking Software
Qt and C++ developers for hire

More information about the Interest mailing list