c++qtqpainterqprinter

Qt - Simple code QPrinter doesn't work on others pc


QPrinter printer(QPrinter::HighResolution);         

    printer.setPageSize(QPrinter::A4);
    printer.setOrientation(QPrinter::Portrait);
    printer.setPageMargins (15,15,15,15,QPrinter::Millimeter);
    printer.setFullPage(false);
    printer.setOutputFormat(QPrinter::NativeFormat);                     


    QPainter painter(&printer);                           

    painter.setFont(QFont("Tahoma",8));
    painter.drawText(200,200,"Test prova prova");
    painter.end();

In the PC with QT the print works right (print works normally), but in the others pc (one with win 8.1 and one with win 7) doesn't start (print doesn't start, the print queue is empty) I don't understand why and i don't get any error.

I use:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPrinter>
#include <QPainter>

and in the .pro:

QT += printsupport
QTPLUGIN += windowsprintersupport

The dll "Qt5PrintSupport" is present inside the folder of course. Sorry for the noob question but I don't understand what I am doing wrong.


Solution

  • You need the windowsprintersupport.dll plugin on the target machine. Setting QTPLUGIN does not work when you are using Qt as DLLs, only if statically linking Qt to your application.