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 <lars.knoll@qt.io>
bb10
Eirik Aavitsland 2017-10-31 13:46:32 +01:00
parent ce08318a46
commit 77ee9bd1d3
1 changed files with 3 additions and 0 deletions

View File

@ -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<QPlatformPixmap::PixelType>(type));
data->resize(w, h);
return data;