diff --git a/src/plugins/platforms/cocoa/qmacclipboard.h b/src/plugins/platforms/cocoa/qmacclipboard.h index 658497f743..925e816831 100644 --- a/src/plugins/platforms/cocoa/qmacclipboard.h +++ b/src/plugins/platforms/cocoa/qmacclipboard.h @@ -30,6 +30,12 @@ private: QPointer mimeData; QVariant variantData; DataRequestType dataRequestType; + // QMimeData can be set from QVariant, holding + // QPixmap. When converting, this triggers + // QPixmap's ctor which in turn requires QGuiApplication + // to exist and thus will abort the application + // abnormally if not. + bool isPixmap = false; }; QList promises; diff --git a/src/plugins/platforms/cocoa/qmacclipboard.mm b/src/plugins/platforms/cocoa/qmacclipboard.mm index 5b77413def..b298a47bef 100644 --- a/src/plugins/platforms/cocoa/qmacclipboard.mm +++ b/src/plugins/platforms/cocoa/qmacclipboard.mm @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -57,9 +58,12 @@ QMacPasteboard::Promise::Promise(int itemId, QMacInternalPasteboardMime *c, QStr // Request the data from the application immediately for eager requests. if (dataRequestType == QMacPasteboard::EagerRequest) { variantData = md->variantData(m); + isPixmap = variantData.metaType().id() == QMetaType::QPixmap; mimeData = nullptr; } else { mimeData = md; + if (md->hasImage()) + isPixmap = md->imageData().metaType().id() == QMetaType::QPixmap; } } @@ -170,8 +174,14 @@ OSStatus QMacPasteboard::promiseKeeper(PasteboardRef paste, PasteboardItemID id, // to request the data from the application. QVariant promiseData; if (promise.dataRequestType == LazyRequest) { - if (!qpaste->resolvingBeforeDestruction && !promise.mimeData.isNull()) + if (!qpaste->resolvingBeforeDestruction && !promise.mimeData.isNull()) { + if (promise.isPixmap && !QGuiApplication::instance()) { + qCWarning(lcQpaClipboard, + "Cannot keep promise, data contains QPixmap and requires livining QGuiApplication"); + return cantGetFlavorErr; + } promiseData = promise.mimeData->variantData(promise.mime); + } } else { promiseData = promise.variantData; }