Looking for help with QPrinter



  • Hello there.

    I'm struggling to get QPrinter to work in my project and I'm hoping someone can point me in the right direction.

    When I build the project I get "'QPrinter' was not declared in this scope". That's basically all I get for errors.

    Within my .cpp file where I'm making a QPrinter object I have:
    #include <QPrinter>

    In my .pro file I have:
    QT += printsupport

    Does anyone have any tips around what I can try to debug this?



  • @Stewguy said in Looking for help with QPrinter:

    QPrinter

    Hi,

    first of, did you rerun qmake / delete your build folder for a clean rebuild after adding QT += printsupport ?
    this is the most common error people have

    second,
    for what platform do you try to use the modul for, IIRC I tried to use it to create a pdf on mobile devices and I had to fall back to QPdfWriter



  • @Stewguy
    After you have acted on @J-Hilk 's comments, your code does not in itself show where you actually attempt to use QPrinter?



  • You could try out one of the examples that uses QPrinter, e.g. the Font Sampler. If you have trouble there as well, it's probably a system or Qt configuration issue. If not, it's probably something in your project.



  • @Asperamanca said in Looking for help with QPrinter:

    You could try out one of the examples that uses QPrinter, e.g. the Font Sampler. If you have trouble there as well, it's probably a system or Qt configuration issue. If not, it's probably something in your project.

    Thanks for pointing out the example, it ended up leading me to the solution.

    What resolved it:

    The QT template added the following lines into my .pro file

    INCLUDEPATH += $$PWD/../../../../Qt/5.11.0/winrt_x86_msvc2017/include
    DEPENDPATH += $$PWD/../../../../Qt/5.11.0/winrt_x86_msvc2017/include

    Something about those was causing QPrinter not to load. Once I removed those lines the project was able to Build and Run.

    Thanks for the help everyone!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.