[Solved] QPrinterInfo::availablePrinters() don't list available printers ?
I spent some time on this problem and I want to share my solution here.
I had a printer problem when deploying my QT application. In the production environment, my application is unable to get the list of available printers from QPrinterInfo::availablePrinters() and in the devlopment environment, everything is working fine !!!
The cause of the problem is that my application is not able to find windowsprintsupport.dll ! The solution I found is to make sure I deploy the rigth windowsprintsupport.dll and to make sure that it can be found by the application !
In my case, I deploy the wrong dll and even though I deploy a dll, it was not found by my application !!!
Here is the detail about the solution I found !
(1) QPrintInfo::availablePrinters() uses windowsprintersupport.dll.
(2) However, in the QT folder, there are two such dll ! Which one must be used ?
(3) The one that must be used is the following : C:\Qt\Qt5.2.0\5.2.0\mingw48_32\plugins\printsupport\windowsprintersupport.dll (which is about 41k).
(4) The windowsprintersupport.dll (which is about 16k) in the following path must *not *be used : C:\Qt\Qt5.2.0\Tools\QtCreator\bin\plugins\printsupport\windowsprintersupport.dll since it is related to QTCreator.
(5) Make sure you have the rigth one.
(6) In your application, make sure you have the following instruction : qApp->addLibraryPath("./plugins"); This instruction allows your application to add a path to let the application find the dll.
(7) In the project file (.pro), make sure to add printsupport to Qt, like the following instruction : QT += core gui sql xml webkitwidgets printsupport.
(8) Find a machine where QT is not installed. This is to make sure that the deployed application will not find the Qt dll in the folder where Qt is installed and that we will be sure that the only place where .windowsprintersupport.dll is located is in the printsupport folder (see below).
(9) Now, suppose you deploy your application in the following folder : c:\MyApp
(10) In this folder, create a folder named "plugins" e.g. c:\MyApp\plugins
(11) In c:\MyApp\plugins, create a folder named "printsupport" e.g. c:\MyApp\plugins\printsupport
(12) In In c:\MyApp\plugins\printsupport, copy the windowsprintsupport dll.
(13) Make sure that *all *other Qt dll needed by your application are also in the c:\MyApp folder
(14) Test your application.
Thank you !
Thanks for sharing your solution with us!