Skip to content

Commit

Permalink
Fix crash if QmlEngineHolder has not been initialized yet
Browse files Browse the repository at this point in the history
  • Loading branch information
oskirby committed Apr 10, 2024
1 parent 3c1f072 commit 2ef4e12
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/platforms/linux/xdgstartatbootwatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,24 @@ void XdgStartAtBootWatcher::xdgResponse(uint response, QVariantMap results) {
// Try to find the window identifier for an XDG desktop portal request.
// https://flatpak.github.io/xdg-desktop-portal/docs/window-identifiers.html
QString XdgStartAtBootWatcher::parentWindow() {
QWindow* window = QmlEngineHolder::instance()->window();
if (window == nullptr) {
if (!QmlEngineHolder::exists()) {
return QString("");
}
QmlEngineHolder* holder = QmlEngineHolder::instance();
if (!holder->hasWindow()) {
return QString("");
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
QGenericUnixServices* services = dynamic_cast<QGenericUnixServices*>(
QGuiApplicationPrivate::platformIntegration()->services());
if (services != nullptr) {
return services->portalWindowIdentifier(window);
return services->portalWindowIdentifier(holder->window());
}
#else
// X11 is the only platform that we can get a window handle on prior to 6.5.0
if (QGuiApplication::platformName() == "xcb") {
return "x11:" + QString::number(window->winId(), 16);
return "x11:" + QString::number(holder->window()->winId(), 16);
}
#endif

Expand Down

0 comments on commit 2ef4e12

Please sign in to comment.