Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Looking for help with QPrinter

    General and Desktop
    4
    5
    464
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Stewguy last edited by

      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?

      J.Hilk JonB 2 Replies Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @Stewguy last edited by

        @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

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply Reply Quote 3
        • JonB
          JonB @Stewguy last edited by

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

          1 Reply Last reply Reply Quote 1
          • A
            Asperamanca last edited by

            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.

            S 1 Reply Last reply Reply Quote 3
            • S
              Stewguy @Asperamanca last edited by

              @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!

              1 Reply Last reply Reply Quote 1
              • First post
                Last post