Issue
How can i catch QApplication::aboutToQuit on Android environment ? It works perfectly on Windows but it's never called when user close the application on Android.
I'm using Qt 5.12.2, QQuick2.
It does not work on Android Emulator and neither on my Android phone.
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QuitEventHandle test;
QObject::connect(&app, &QCoreApplication::aboutToQuit, &test, &QuitEventHandle::aboutToQuit);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
class QuitEventHandle : public QObject
{
Q_OBJECT
public:
QuitEventHandle(QObject *parent=nullptr);
virtual ~QuitEventHandle() override;
public slots:
void aboutToQuit();
};
QuitEventHandle::QuitEventHandle(QObject *parent) : QObject(parent)
{
}
QuitEventHandle::~QuitEventHandle()
{
}
void QuitEventHandle::aboutToQuit()
{
int a = 2;
}
Solution
My solution :
- Use
QGuiApplication::applicationStateChanged
to save application's states. - In the case of Windows, clean up the resource with:
QApplication::aboutToQuit
- In the case of Android, let the system clean up the resource.
Answered By - LE Xuan Hung
Answer Checked By - Timothy Miller (JavaFixing Admin)