Qt Android application. Backround swipe closure handling
-
wrote on 25 Jun 2019, 09:53 last edited by
Hi guys,
I need help with clean exit when user shuts down application from background (swipe quit/kill).
I want to call method from class that is written in C++, in onDestroy() method.
Problem is that one is .java and other .cppIs there a way, and how, to handle that swipe from .cpp file or it must be done in .java?
-
wrote on 25 Jun 2019, 10:05 last edited by
-
wrote on 27 Jun 2019, 12:15 last edited by
I have found what is the problem, but still cannot find the solution.
When i press BACK BUTTON, this is the order of events:
1. closeEvent() ---> most important thing for my app, cleanup done there
2. onPause
3. onStop
4. onDestroyBut when i press HOME BUTTON, this is the order of events:
2. onPause
3. onStop
4. onDestroyI tried adding finish(), but even that is not working(closeEvent() is ALWAYS missing )
Can anyone tell me am i doing something wrong or how can mimic BACK BUTTON by pressing HOME BUTTON?
-
I have found what is the problem, but still cannot find the solution.
When i press BACK BUTTON, this is the order of events:
1. closeEvent() ---> most important thing for my app, cleanup done there
2. onPause
3. onStop
4. onDestroyBut when i press HOME BUTTON, this is the order of events:
2. onPause
3. onStop
4. onDestroyI tried adding finish(), but even that is not working(closeEvent() is ALWAYS missing )
Can anyone tell me am i doing something wrong or how can mimic BACK BUTTON by pressing HOME BUTTON?
@Stasa-Sekulic
well, on mobile, when your app gets pushed into the back ground, the application state is changed to suspendedhttps://doc.qt.io/qt-5/qguiapplication.html#applicationStateChanged
you could listen for that signal and react accordingly ?
-
wrote on 27 Jun 2019, 13:10 last edited by
-
@J-Hilk
Thanks for the hint!
Problem is that my class is derived from QWidget.
Or can i emit close signal from one class to another?@Stasa-Sekulic
if you add#include <QGuiApplication>
to your class, than you have access to theqApp
global pointer of your QGuiApplication instance. You can use that to connect to the signal -
wrote on 1 Jul 2019, 08:53 last edited by
@J-Hilk
Thanks! I have implemented everything that you said and IT WORKS!
I summary i have done next:
I have connected my QCoreApplication with my widget like this
connect(QCoreApplication::instance(), SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(state_changed_event(Qt::ApplicationState)));and inside my state_changed_event slot i am handling state when application is suspended.
Main idea was to handle force closure of application from background, i suppose this is not the correct solution, but this workaround is handling that ok for now.
1/7