Skip to content

Commit 1ef5537

Browse files
committed
Close splash screen instead of hiding it
With Qt 5, this fixes a bug where (on Linux at least) the entire program closes if you click the X in the file dialog. On Qt 6 things are much more broken without this commit. If the splash screen is just hidden instead of closed, it keeps the application alive indefinitely. So we must close the splash screen instead of hiding it to use the automatic exiting feature. But with the way we were creating the windows before, the other windows were descendants of the splash screen for memory management purposes and closing the splash screen would remove them. So I added a new global object to be the QObject parent for other top-level windows.
1 parent 53f93bb commit 1ef5537

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,13 @@ int main(int argc, char *argv[])
216216
engine.addImportPath(QLatin1String("qrc:/"));
217217
engine.addImageProvider(QLatin1String("fluidicons"), new IconsImageProvider());
218218
engine.addImageProvider(QLatin1String("fluidicontheme"), new IconThemeImageProvider());
219+
220+
// Top-level windows can be attached to this so that they aren't QObject-children of the
221+
// splash screen. Must destruct before engine.
222+
QObject motherOfWindows;
223+
219224
auto* context = engine.rootContext();
225+
context->setContextProperty("motherOfWindows", &motherOfWindows);
220226
context->setContextProperty("updaterSettings", &settings);
221227
context->setContextProperty("gameLauncher", &gameLauncher);
222228
context->setContextProperty("splashController", &splashController);

splash.qml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ ApplicationWindow {
5353

5454
function showUpdater() {
5555
splashDownloaderConnections.enabled = false;
56-
updaterWindowLoader.active = true
57-
splash.hide();
56+
var mainWindowComponent = Qt.createComponent("main.qml");
57+
mainWindowComponent.createObject(motherOfWindows);
58+
splash.close();
5859
}
5960

6061
Connections {
@@ -96,10 +97,8 @@ ApplicationWindow {
9697
target: downloader
9798

9899
function onFatalMessage(message) {
99-
updateFailed.errorDetail = message;
100-
updateFailedWindow.show();
101-
updateFailed.open();
102-
splash.hide();
100+
updateFailedComponent.createObject(motherOfWindows, { errorDetail: message });
101+
splash.close();
103102
}
104103
}
105104

@@ -166,15 +165,10 @@ ApplicationWindow {
166165
Material.accent: Material.Teal
167166
}
168167

169-
Loader {
170-
id: updaterWindowLoader
171-
active: false
172-
source: "qrc:/main.qml"
173-
}
168+
property Component updateFailedComponent: ApplicationWindow {
169+
property alias errorDetail: updateFailed.errorDetail
174170

175-
ApplicationWindow {
176-
id: updateFailedWindow
177-
visible: false
171+
visible: true
178172
width: updateFailed.width
179173
height: updateFailed.height
180174
maximumWidth: updateFailed.width
@@ -183,5 +177,6 @@ ApplicationWindow {
183177
id: updateFailed
184178
failedOperation: 'Launcher self-update'
185179
}
180+
Component.onCompleted: updateFailed.open()
186181
}
187182
}

0 commit comments

Comments
 (0)