Stop desktop app window's QML source from running when window is closed

This commit is contained in:
David Rowe 2018-06-20 15:48:40 +12:00
parent 97e4d2eb46
commit 764e00d9cf
3 changed files with 31 additions and 0 deletions

View file

@ -286,6 +286,13 @@ void OffscreenSurface::loadInternal(const QUrl& qmlSource,
if (QThread::currentThread() != thread()) {
qFatal("Called load on a non-surface thread");
}
// For desktop toolbar mode window: stop script when window is closed.
if (qmlSource.isEmpty()) {
getSurfaceContext()->engine()->quit();
return;
}
// Synchronous loading may take a while; restart the deadlock timer
QMetaObject::invokeMethod(qApp, "updateHeartbeat", Qt::DirectConnection);

View file

@ -648,6 +648,26 @@ void TabletProxy::loadQMLSource(const QVariant& path, bool resizable) {
}
}
void TabletProxy::stopQMLSource() {
// For desktop toolbar mode dialogs.
if (!_toolbarMode || !_desktopWindow) {
qCDebug(uiLogging) << "tablet cannot clear QML because not desktop toolbar mode";
return;
}
auto root = _desktopWindow->asQuickItem();
if (root) {
QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, ""));
if (!_currentPathLoaded.toString().isEmpty()) {
emit screenChanged(QVariant("QML"), "");
}
_currentPathLoaded = "";
_state = State::Home;
} else {
qCDebug(uiLogging) << "tablet cannot clear QML because _desktopWindow is null";
}
}
bool TabletProxy::pushOntoStack(const QVariant& path) {
if (QThread::currentThread() != thread()) {
bool result = false;
@ -719,6 +739,7 @@ void TabletProxy::loadHomeScreen(bool forceOntoHomeScreen) {
// close desktop window
if (_desktopWindow->asQuickItem()) {
QMetaObject::invokeMethod(_desktopWindow->asQuickItem(), "setShown", Q_ARG(const QVariant&, QVariant(false)));
stopQMLSource(); // Stop the currently loaded QML running.
}
}
_state = State::Home;

View file

@ -443,6 +443,9 @@ protected:
bool _showRunningScripts { false };
TabletButtonListModel _buttons;
private:
void stopQMLSource();
};
Q_DECLARE_METATYPE(TabletProxy*);