From 54a2a547470cdb2762876acdb41d20a463bb8913 Mon Sep 17 00:00:00 2001 From: Daniel Bermond Date: Sat, 30 Mar 2024 11:05:16 -0300 Subject: [PATCH] X11 Qt6: fix segmentation fault when running under Wayland Under Wayland, 'QGuiApplication::nativeInterface()' seems to return a null pointer. At least, this happens in Plasma 6.0.3 with Qt 6.6.2. A segmentation fault occurs when dereferencing the null pointer for obtaining the X11 display. Checking for a valid pointer in 'x11Interface' variable before acquiring the X11 display is safer and avoids this problem. --- QHotkey/qhotkey_x11.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/QHotkey/qhotkey_x11.cpp b/QHotkey/qhotkey_x11.cpp index d3ac1d1..0c30608 100644 --- a/QHotkey/qhotkey_x11.cpp +++ b/QHotkey/qhotkey_x11.cpp @@ -132,7 +132,10 @@ quint32 QHotkeyPrivateX11::nativeKeycode(Qt::Key keycode, bool &ok) #if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) const QNativeInterface::QX11Application *x11Interface = qGuiApp->nativeInterface(); - Display *display = x11Interface->display(); + Display *display = nullptr; + + if (x11Interface) + display = x11Interface->display(); #else const bool x11Interface = QX11Info::isPlatformX11(); Display *display = QX11Info::display();