0

I have opened and focused app on android phone, and I lock the screen. When I unlock it, I want to call a specific function.

I was thinking about Qt.application.state, but how to call function when it has changed?

Asif Patel
  • 1,744
  • 1
  • 20
  • 27

1 Answers1

2

You searching for void QGuiApplication::applicationStateChanged(Qt::ApplicationState state).

From Qt documentation:

void QGuiApplication::applicationStateChanged(Qt::ApplicationState state)

This signal is emitted when the state of the application changes.

This function was introduced in Qt 5.2.

Just connect to this signal at your C++ part of code, check state == Qt::ApplicationActive and trigger some function inside you QML part.

Evgeny
  • 3,910
  • 2
  • 20
  • 37
  • what is wrong? `QObject::connect(app, SIGNAL(app.applicationStateChanged(Qt::ApplicationState state)), &stater, SLOT(stateChanged()));` –  Feb 23 '17 at 20:22
  • Should be `QObject::connect(&app, SIGNAL(applicationStateChanged(Qt::ApplicationState state)), &stater, SLOT(stateChanged()));` – Evgeny Feb 23 '17 at 20:53