Index: qtbase-opensource-src-5.6.2/src/plugins/printsupport/cups/qcupsprintersupport.cpp
===================================================================
--- qtbase-opensource-src-5.6.2.orig/src/plugins/printsupport/cups/qcupsprintersupport.cpp
+++ qtbase-opensource-src-5.6.2/src/plugins/printsupport/cups/qcupsprintersupport.cpp
@@ -46,6 +46,34 @@
 # include <cups/language.h>
 #endif
 
+typedef struct
+{
+    cups_dest_t *printers;
+    int num_printers;
+} EnumDestsContext;
+
+static int enum_dest_cb (void *user_data, unsigned flags, cups_dest_t *dest)
+{
+   EnumDestsContext *context = (EnumDestsContext *) user_data;
+   if ((flags & (CUPS_DEST_FLAGS_UNCONNECTED |
+                 CUPS_DEST_FLAGS_REMOVED |
+                 CUPS_DEST_FLAGS_ERROR |
+                 CUPS_DEST_FLAGS_RESOLVING |
+                 CUPS_DEST_FLAGS_CONNECTING |
+                 CUPS_DEST_FLAGS_CANCELED)) == 0) {
+
+       context->num_printers = cupsCopyDest (dest, context->num_printers,
+                                              &context->printers);
+
+       // Also copy whether this is the local default /
+       cups_dest_t *the_dest;
+       the_dest = cupsGetDest(dest->name, dest->instance,
+                               context->num_printers, context->printers);
+       the_dest->is_default = dest->is_default;
+   }
+   return 1;
+}
+
 QT_BEGIN_NAMESPACE
 
 QCupsPrinterSupport::QCupsPrinterSupport()
@@ -75,17 +103,36 @@ QPrintDevice QCupsPrinterSupport::create
 
 QStringList QCupsPrinterSupport::availablePrintDeviceIds() const
 {
-    QStringList list;
+/*  // Reset cache disabled for now: We only load the list of printers
+    // once per process. We could add a timeout here
+    if (qt_cups_printers) {
+        cupsFreeDests( qt_cups_num_printers, qt_cups_printers );
+        qt_cups_printers = NULL;
+        qt_cups_num_printers = 0;
+    }
+*/
     cups_dest_t *dests;
-    int count = cupsGetDests(&dests);
-    list.reserve(count);
-    for (int i = 0; i < count; ++i) {
+    bool disablePrinterDiscovery = qEnvironmentVariableIsSet("QT_DISABLE_PRINTER_DISCOVERY");
+    if (disablePrinterDiscovery) {
+        qt_cups_num_printers = cupsGetDests(&dests);
+    } else {
+        if (qt_cups_num_printers == 0)
+            QCupsPrinterSupport::fillCupsPrinters();
+
+        dests = qt_cups_printers;
+    }
+    QStringList list;
+    list.reserve(qt_cups_num_printers);
+    for (int i = 0; i < qt_cups_num_printers; ++i) {
         QString printerId = QString::fromLocal8Bit(dests[i].name);
         if (dests[i].instance)
             printerId += QLatin1Char('/') + QString::fromLocal8Bit(dests[i].instance);
         list.append(printerId);
     }
-    cupsFreeDests(count, dests);
+    if (disablePrinterDiscovery) {
+        cupsFreeDests(qt_cups_num_printers, dests);
+    }
+
     return list;
 }
 
@@ -93,8 +140,18 @@ QString QCupsPrinterSupport::defaultPrin
 {
     QString printerId;
     cups_dest_t *dests;
-    int count = cupsGetDests(&dests);
-    for (int i = 0; i < count; ++i) {
+
+    bool disablePrinterDiscovery = qEnvironmentVariableIsSet("QT_DISABLE_PRINTER_DISCOVERY");
+    if (disablePrinterDiscovery) {
+        qt_cups_num_printers = cupsGetDests(&dests);
+    } else {
+        if (qt_cups_num_printers == 0)
+            QCupsPrinterSupport::fillCupsPrinters();
+
+        dests = qt_cups_printers;
+    }
+
+    for (int i = 0; i < qt_cups_num_printers; ++i) {
         if (dests[i].is_default) {
             printerId = QString::fromLocal8Bit(dests[i].name);
             if (dests[i].instance) {
@@ -103,8 +160,27 @@ QString QCupsPrinterSupport::defaultPrin
             }
         }
     }
-    cupsFreeDests(count, dests);
+    if (disablePrinterDiscovery) {
+        cupsFreeDests(qt_cups_num_printers, dests);
+    }
     return printerId;
 }
 
+void QCupsPrinterSupport::fillCupsPrinters()
+{
+    EnumDestsContext context;
+    context.printers = 0;
+    context.num_printers = 0;
+
+    cupsEnumDests(CUPS_DEST_FLAGS_NONE, 4000, NULL, 0, 0,
+                   enum_dest_cb, &context);
+
+    qt_cups_printers = context.printers;
+    qt_cups_num_printers = context.num_printers;
+}
+
+cups_dest_t *QCupsPrinterSupport::qt_cups_printers = NULL;
+int QCupsPrinterSupport::qt_cups_num_printers = 0;
+
+
 QT_END_NAMESPACE
Index: qtbase-opensource-src-5.6.2/src/plugins/printsupport/cups/qcupsprintengine.cpp
===================================================================
--- qtbase-opensource-src-5.6.2.orig/src/plugins/printsupport/cups/qcupsprintengine.cpp
+++ qtbase-opensource-src-5.6.2/src/plugins/printsupport/cups/qcupsprintengine.cpp
@@ -42,6 +42,7 @@
 #include <qbuffer.h>
 #include "private/qcups_p.h" // Only needed for PPK_CupsOptions
 #include <QtGui/qpagelayout.h>
+#include "qcupsprintersupport_p.h"
 
 #include <cups/cups.h>
 
@@ -235,8 +236,39 @@ void QCupsPrintEnginePrivate::closePrint
 
         // Print the file.
         cups_option_t* optPtr = cupsOptStruct.size() ? &cupsOptStruct.first() : 0;
-        cupsPrintFile(printerName.toLocal8Bit().constData(), tempFile.toLocal8Bit().constData(),
+
+        bool fallbackToLocal = false;
+        cups_dest_t *cupsDest = NULL;
+
+        if (qEnvironmentVariableIsSet("QT_DISABLE_PRINTER_DISCOVERY")) {
+            fallbackToLocal = true;
+        } else {
+            cupsDest = cupsGetDest(printerName.toLocal8Bit(), NULL, QCupsPrinterSupport::cupsPrintersCount(), QCupsPrinterSupport::cupsPrinters());
+        }
+
+        if (cupsDest) {
+            char resource[HTTP_MAX_URI];
+            http_t *http = cupsConnectDest (cupsDest, 0, -1, 0,
+                                         resource, sizeof (resource),
+                                         0, 0);
+            if (http) {
+                char *name = strrchr (resource, '/');
+                if (name)
+                    cupsPrintFile2 (http, ++name, tempFile.toLocal8Bit().constData(),
                       title.toLocal8Bit().constData(), cupsOptStruct.size(), optPtr);
+                httpClose(http);
+            } else {
+                fallbackToLocal=true;
+            }
+        }
+        else {
+            fallbackToLocal=true;
+        }
+
+        if (fallbackToLocal) {
+            cupsPrintFile(printerName.toLocal8Bit().constData(), tempFile.toLocal8Bit().constData(),
+                          title.toLocal8Bit().constData(), cupsOptStruct.size(), optPtr);
+        }
 
         QFile::remove(tempFile);
     }
Index: qtbase-opensource-src-5.6.2/src/plugins/printsupport/cups/qcupsprintersupport_p.h
===================================================================
--- qtbase-opensource-src-5.6.2.orig/src/plugins/printsupport/cups/qcupsprintersupport_p.h
+++ qtbase-opensource-src-5.6.2/src/plugins/printsupport/cups/qcupsprintersupport_p.h
@@ -50,6 +50,8 @@
 
 #include <QtCore/qstringlist.h>
 
+#include <cups/cups.h>
+
 QT_BEGIN_NAMESPACE
 
 class QCupsPrinterSupport : public QPlatformPrinterSupport
@@ -65,8 +67,14 @@ public:
     QStringList availablePrintDeviceIds() const Q_DECL_OVERRIDE;
     QString defaultPrintDeviceId() const Q_DECL_OVERRIDE;
 
+    static void fillCupsPrinters();
+    static cups_dest_t *cupsPrinters() { return qt_cups_printers; };
+    static int cupsPrintersCount() { return qt_cups_num_printers; };
 private:
     QString cupsOption(int i, const QString &key) const;
+
+    static cups_dest_t *qt_cups_printers;
+    static int qt_cups_num_printers;
 };
 
 QT_END_NAMESPACE
Index: qtbase-opensource-src-5.6.2/src/plugins/printsupport/cups/qppdprintdevice.cpp
===================================================================
--- qtbase-opensource-src-5.6.2.orig/src/plugins/printsupport/cups/qppdprintdevice.cpp
+++ qtbase-opensource-src-5.6.2/src/plugins/printsupport/cups/qppdprintdevice.cpp
@@ -35,6 +35,7 @@
 
 #include <QtCore/QMimeDatabase>
 #include <qdebug.h>
+#include "qcupsprintersupport_p.h"
 
 #ifndef QT_LINUXBASE // LSB merges everything into cups.h
 #include <cups/language.h>
@@ -445,10 +446,38 @@ void QPpdPrintDevice::loadPrinter()
         m_cupsDest = 0;
     }
 
+    bool disablePrinterDiscovery = qEnvironmentVariableIsSet("QT_DISABLE_PRINTER_DISCOVERY");
+
     // Get the print instance and PPD file
-    m_cupsDest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, m_cupsName, m_cupsInstance);
+
+    if (disablePrinterDiscovery) {
+        m_cupsDest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, m_cupsName, m_cupsInstance);
+    } else {
+        cups_dest_t *cupsDest = cupsGetDest( m_cupsName,
+                                         (m_cupsInstance.isEmpty() ? NULL : m_cupsInstance.data()),
+                                         QCupsPrinterSupport::cupsPrintersCount(),
+                                         QCupsPrinterSupport::cupsPrinters() );
+        cupsCopyDest(cupsDest, 0, &m_cupsDest);
+    }
     if (m_cupsDest) {
-        const char *ppdFile = cupsGetPPD(m_cupsName);
+        char resource[HTTP_MAX_URI];
+        http_t *http = NULL;
+        const char *ppdFile = NULL;
+
+        if (!disablePrinterDiscovery) {
+            http = cupsConnectDest (m_cupsDest, 0, -1, 0,
+                             resource, sizeof (resource),
+                             0, 0);
+        }
+        if (http) {
+            char *name = strrchr (resource, '/');
+            if (name)
+                ppdFile = cupsGetPPD2 (http, ++name);
+            httpClose(http);
+        } else {
+            ppdFile = cupsGetPPD(m_cupsName);
+        }
+
         if (ppdFile) {
             m_ppd = ppdOpenFile(ppdFile);
             unlink(ppdFile);
