Initalize the printinfo on Mac if it requests and it needs initalizing
authorAndy Shaw <andy.shaw@digia.com>
Mon, 17 Dec 2012 21:46:45 +0000 (22:46 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 18 Dec 2012 06:21:19 +0000 (07:21 +0100)
When the print panel was closed then it would clean up the printinfo
and if it was requested for the same QPrinter then it would not be
recreated in time. Therefore we check if it is initalized and if not
we re-initalize it.

Task-number: QTBUG-28657
Change-Id: I7dc9011b80e03cfa3eae8fee2fcf6cc8021a8566
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
(cherry picked from commit dde9569d389b4382e8869ac48f942adb3c51ade7)
Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
src/plugins/platforms/cocoa/qcocoanativeinterface.mm

index f0b1bd3..271c9d2 100644 (file)
@@ -107,8 +107,10 @@ QPlatformPrinterSupport *QCocoaNativeInterface::createPlatformPrinterSupport()
 void *QCocoaNativeInterface::NSPrintInfoForPrintEngine(QPrintEngine *printEngine)
 {
 #ifndef QT_NO_WIDGETS
-    QMacPrintEngine *macPrintEngine = static_cast<QMacPrintEngine *>(printEngine);
-    return macPrintEngine->d_func()->printInfo;
+    QMacPrintEnginePrivate *macPrintEnginePriv = static_cast<QMacPrintEngine *>(printEngine)->d_func();
+    if (macPrintEnginePriv->state == QPrinter::Idle && !macPrintEnginePriv->isPrintSessionInitialized())
+        macPrintEnginePriv->initialize();
+    return macPrintEnginePriv->printInfo;
 #else
     qFatal("Printing is not supported when Qt is configured with -no-widgets");
     return 0;