From 799621c0e235d41021b2785b690bfd0d1f44db11 Mon Sep 17 00:00:00 2001 From: David Faure Date: Sat, 23 Feb 2013 17:27:09 +0100 Subject: Fix crash when qApp is a QCoreApplication. Yes, it makes little sense to call QX11Info API in such cases; but it happens currently in kio unittests which calls code which creates dialogs but never show them to the user (since they are unittests). With this fix, the tests pass. Change-Id: I96cd2080891a960aa405d98fd1801253930bde1e Reviewed-by: Friedemann Kleint --- src/x11extras/qx11info_x11.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/x11extras/qx11info_x11.cpp b/src/x11extras/qx11info_x11.cpp index cb534b7..a7499e4 100644 --- a/src/x11extras/qx11info_x11.cpp +++ b/src/x11extras/qx11info_x11.cpp @@ -187,6 +187,8 @@ unsigned long QX11Info::appTime() if (!qApp) return 0; QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return 0; QScreen* screen = QGuiApplication::primaryScreen(); return static_cast(reinterpret_cast(native->nativeResourceForScreen("apptime", screen))); } @@ -201,6 +203,8 @@ unsigned long QX11Info::appUserTime() if (!qApp) return 0; QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return 0; QScreen* screen = QGuiApplication::primaryScreen(); return static_cast(reinterpret_cast(native->nativeResourceForScreen("appusertime", screen))); } @@ -215,6 +219,8 @@ void QX11Info::setAppTime(unsigned long time) if (!qApp) return; QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return; typedef void (*SetAppTimeFunc)(QScreen *, xcb_timestamp_t); QScreen* screen = QGuiApplication::primaryScreen(); SetAppTimeFunc func = reinterpret_cast(native->nativeResourceFunctionForScreen("setapptime")); @@ -234,6 +240,8 @@ void QX11Info::setAppUserTime(unsigned long time) if (!qApp) return; QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return; typedef void (*SetAppUserTimeFunc)(QScreen *, xcb_timestamp_t); QScreen* screen = QGuiApplication::primaryScreen(); SetAppUserTimeFunc func = reinterpret_cast(native->nativeResourceFunctionForScreen("setappusertime")); @@ -253,6 +261,8 @@ Display *QX11Info::display() if (!qApp) return NULL; QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return NULL; void *display = native->nativeResourceForScreen(QByteArray("display"), QGuiApplication::primaryScreen()); return reinterpret_cast(display); @@ -268,6 +278,8 @@ xcb_connection_t *QX11Info::connection() if (!qApp) return NULL; QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return NULL; void *connection = native->nativeResourceForWindow(QByteArray("connection"), 0); return reinterpret_cast(connection); -- cgit v1.2.1