From 4aebbef8ab94723d59679f30005b114197c995b9 Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Tue, 22 Nov 2016 11:55:50 +0000 Subject: Add support for selecting the printer plugin via the env var Task-number: QTBUG-57260 Change-Id: I046c8ce5af242cdc7efd23468bbe670d782bdfc0 Reviewed-by: Friedemann Kleint Reviewed-by: Andy Shaw --- src/printsupport/kernel/qplatformprintplugin.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/printsupport/kernel/qplatformprintplugin.cpp b/src/printsupport/kernel/qplatformprintplugin.cpp index 9bc4b61829..a80f369040 100644 --- a/src/printsupport/kernel/qplatformprintplugin.cpp +++ b/src/printsupport/kernel/qplatformprintplugin.cpp @@ -42,6 +42,7 @@ #include "qprinterinfo.h" #include "private/qfactoryloader_p.h" #include +#include #ifndef QT_NO_PRINTER @@ -79,8 +80,17 @@ QPlatformPrinterSupport *QPlatformPrinterSupportPlugin::get() { if (!printerSupport) { const QMultiMap keyMap = loader()->keyMap(); - if (!keyMap.isEmpty()) - printerSupport = qLoadPlugin(loader(), keyMap.constBegin().value()); + QMultiMap::const_iterator it = keyMap.cbegin(); + if (!qEnvironmentVariableIsEmpty("QT_PRINTER_MODULE")) { + QString module = QString::fromLocal8Bit(qgetenv("QT_PRINTER_MODULE")); + QMultiMap::const_iterator it2 = std::find_if(keyMap.cbegin(), keyMap.cend(), [module](const QString &value){ return value == module; }); + if (it2 == keyMap.cend()) + qWarning() << "Unable to load printer plugin" << module; + else + it = it2; + } + if (it != keyMap.cend()) + printerSupport = qLoadPlugin(loader(), it.value()); if (printerSupport) qAddPostRoutine(cleanupPrinterSupport); } -- cgit v1.2.3