Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPrinter issues
Qt 6.11 is out! See what's new in the release blog

QPrinter issues

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 Posters 3.2k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    MrShawn
    wrote on last edited by
    #1

    Hey guys,

    So I am having a strange issue where QPrinter works fine in one qt project and doesn't in the other. I am using Qt 5.10 ( I am tempted to say it is NOT the version but it could be).

    I made a simple project which basically runs this chunk of code just fine.

        QPrinter myPrinter;
        if (myPrinter.isValid())
        {
            qDebug() << myPrinter.printerName();
            QTextDocument doc("Test page!\nAnother Line!");
            doc.print(&myPrinter);
        }
        qDebug() << QPrinterInfo::availablePrinterNames();
    

    It prints a few lines to the default printer. Later I print out all available printers to check some things and look at what APrinterInfo has to offer. That is basically all it does it is a blank application project where i run this in main window constructor.

    My other project essentially runs the same code but cannot seem to not find my printers and I am not sure why. The printer name is blank. The available printer list empty. No default printer exists either. I have the printsupport added to the .pro file in both projects, if I didn't simply adding the printer includes would not work. It is also the same machine so it should see the same printers.

    I will be actively working to resolve this issue but if there are any pointers/ideas I would greatly appreciate it.

    Thanks,
    Shawn

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi,

      Let's start by a maybe silly question: are you using the same kit to build both applications ?
      Are you starting both from Qt Creator ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MrShawn
        wrote on last edited by
        #3

        Yes, and yes.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then I'd check for differences in the environment variables in the build and the run parts of the Project panel.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MrShawn
            wrote on last edited by
            #5

            Everything looks to be the same beside the specific differences in the .pro files names

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MrShawn
              wrote on last edited by
              #6

              Do I need to free the printer resource? For example if I open a serial port that resource is in use to another program unless you close it first. I see no QPrinter.close() or something like that so I assume that is not case.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Do you mean it happens if you run both application at the same time ?

                What OS are you running ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MrShawn
                  wrote on last edited by
                  #8

                  I run them at different times. What I mean is that I can open the serial resource in a test program (and fail to close it when the program ends) and any other call to open the serial resource will claim its in use until the resource is closed. I am wondering if this behaves in a similar manner.

                  I made the small one to test how to print things, then I basically added the code to my other project after I figured it out. In my test project it worked fine. Now in my other project it doesn't work. I can run the test one at any time and it works.

                  Windows 7 pro

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    How are you handling the printing in your big project ? What is different than from your small project ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • M Offline
                      M Offline
                      MrShawn
                      wrote on last edited by
                      #10

                      Honestly the only difference is that I generate the string for the QTextDocument constructor, which should have no effect on setting up my QPrinter and seeing printers (to my knowledge).

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        MrShawn
                        wrote on last edited by
                        #11

                        The good news is I got it working!

                        @SGaist not sure if you have insight as to why but I did do clean, ran qmake, and build several times. In the end I changed the build directory to be totally fresh. When I did that and rebuilt into the new directory it worked just fine.

                        @SGaist Thanks a lot for helping, I appreciate it!

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved