From 76516c7651e41d46ab685e884a3cb1580e048787 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Mon, 3 Mar 2014 18:24:06 +0100 Subject: [PATCH] Fix crash that occurs if the CUPS library sets printers to zero. Change-Id: I64bea3a9e472ff8ae9cac24e67747efd020e6d61 --- src/gui/painting/qcups.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gui/painting/qcups.cpp b/src/gui/painting/qcups.cpp index 99ea43f..7093eb0 100644 --- a/src/gui/painting/qcups.cpp +++ b/src/gui/painting/qcups.cpp @@ -87,6 +87,8 @@ static CupsPrintFile _cupsPrintFile = 0; static void resolveCups() { + cupsLoaded = false; + QLibrary cupsLib(QLatin1String("cups"), 2); if(cupsLib.load()) { _cupsGetDests = (CupsGetDests) cupsLib.resolve("cupsGetDests"); @@ -111,9 +113,9 @@ static void resolveCups() if (num_printers) _cupsFreeDests(num_printers, printers); qt_cups_num_printers = num_printers; + cupsLoaded = true; } } - cupsLoaded = true; } // ================ CUPS Support class ======================== @@ -126,9 +128,6 @@ QCUPSSupport::QCUPSSupport() currPrinterIndex(0), currPPD(0) { - if (!cupsLoaded) - resolveCups(); - // getting all available printers if (!isAvailable()) return; @@ -249,6 +248,9 @@ const ppd_option_t* QCUPSSupport::ppdOption(const char *key) const const cups_option_t* QCUPSSupport::printerOption(const QString &key) const { + resolveCups(); + if (!printers) return 0; + for (int i = 0; i < printers[currPrinterIndex].num_options; ++i) { if (QLatin1String(printers[currPrinterIndex].options[i].name) == key) return &printers[currPrinterIndex].options[i]; -- 1.7.9.5