Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Deployed Qt5 Application Doesn't Print or Show Print Dialog

I'm experiencing Qt4 to Qt5 troubles. In my application when the user clicks the print button two things should happen, one is that a PDF gets written to disk (which still works fine in the new version, so I know that some of the printing functions are working properly) and the other is that a QPrintDialog should exec() and then send to a connected printer.

I see the dialog when I launch from my development machine. The application launches on the deployed machine, but the QPrintDialog never shows and the document never prints.

I am including print support.

QT += core gui network webkitwidgets widgets printsupport

I have been using Process Explorer to see what DLLs the application uses on my development machine, and I believe that everything is present. My application bundle includes:

  • {myAppPath}\MyApp[MyApp.exe, Qt5PrintSupport.dll, ...]
  • {myAppPath}\plugins\printsupport\windowsprintersupport.dll
  • {myAppPath}\plugins\imageformats[ qgif.dll, qico.dll,qjpeg.dll, qmng.dll, qtga.dll, qtiff.dll, qwbmp.dll ]

The following is the relevant code snippet:

void PrintableForm::printFile()
    //Writes the PDF to disk in every environment

    //Paper Copy only works on my dev machine
    QPrinter paperPrinter;
    QPrintDialog printDialog(&paperPrinter,this);

    if( printDialog.exec() == QDialog::Accepted ) {

My first thought is that the relevant DLLs are not being found come print time, and that means that my application file system is incorrect, but I have not found anything that shows me a different file structure. Am I on the right track or is there something else wrong with this setup?

like image 625
RegularlyScheduledProgramming Avatar asked Mar 24 '23 12:03


1 Answers

This was another classic Windows/Qt5 deployment problem with a combination of missing plugins and plugins placed in incorrect places. By using the environmental variable QT_DEBUG_PLUGIN and adding CONFIG += CONSOLE to my PRO file I was able to see that on my development machine the application was loading qminimal.dll which I was not shipping.

The application root which I have defined as {myAppPath}\ is the root directory for plugins. Therefore the correct file structure is:

  • {myAppPath}\MyApp[MyApp.exe, Qt5PrintSupport.dll, ...]
  • {myAppPath}\platforms[qwindows.dll,qminimal.dll]
  • {myAppPath}\printsupport*
  • {myAppPath}\imageformats*
  • {myAppPath}\bearer*

Thanks peppe for the lead.

like image 127
RegularlyScheduledProgramming Avatar answered Apr 07 '23 05:04