From 77ee9bd1d3917b2bb1e442433ef0189e9e281e51 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Tue, 31 Oct 2017 13:46:32 +0100 Subject: QPixmap without QGuiApplication: do not crash, terminate gracefully Any attempt to create a non-null QPixmap in a QCoreApplication-based app would give a hard crash without a warning. This commit adds a check and instead calls qFatal with an explanatory message. This was originally fixed in Qt 4 (ref. QTBUG-17873) but that was lost in the migration to Qt 5. Note that this fix still allows null QPixmaps to be created under QCoreApplication, since that has worked in all Qt 5 versions. Task-number: QTBUG-53572 Task-number: QTBUG-64125 Change-Id: I60ae29b90f1bd3663aeed2ce88dc1690fe66552c Reviewed-by: Lars Knoll --- src/gui/image/qplatformpixmap.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gui/image/qplatformpixmap.cpp b/src/gui/image/qplatformpixmap.cpp index 00c21a5f54..b3b9f79fb1 100644 --- a/src/gui/image/qplatformpixmap.cpp +++ b/src/gui/image/qplatformpixmap.cpp @@ -58,6 +58,9 @@ QT_BEGIN_NAMESPACE */ QPlatformPixmap *QPlatformPixmap::create(int w, int h, PixelType type) { + if (Q_UNLIKELY(!QGuiApplicationPrivate::platformIntegration())) + qFatal("QPlatformPixmap: QGuiApplication required"); + QPlatformPixmap *data = QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(static_cast(type)); data->resize(w, h); return data; -- cgit v1.2.3