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. QPainter.begin returns false on prod machine
Forum Updated to NodeBB v4.3 + New Features

QPainter.begin returns false on prod machine

Scheduled Pinned Locked Moved Solved General and Desktop
qt5.2.1qprinterqpainterpdfwindows
11 Posts 4 Posters 5.5k Views 3 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.
  • P Offline
    P Offline
    PierreFIL
    wrote on last edited by
    #1

    Hi everyone,

    I have an issue using QPrinter and QPainter in my application : I want to print a QWidget as a PDF file. It works perfectly on my development machine, but on the Prod machine, it doesn't. So I guess I have a configuration problem.

    Here is the guity piece of code :

    QPrinter l_oPrinter;
    l_oPrinter.setOutputFormat(QPrinter::PdfFormat)
    l_oPrinter.setOutputFileName(/* something */);
    l_oPrinter.setPaperSize(QPrinter::A4);
    l_oPrinter.setPageMargins(50, 50, 50, 50, QPrinter::DevicePixel);
    // l_oPrinter.isValid() returns true
    
    QPainter l_oPainter;
    if ( l_oPainter.begin(&l_oPrinter) ) // returns false on Prod machine, true on development one
    {
    	ui.wdg_All->render(&l_oPainter); // ui.wdg_All is the QWidget I want to print
    	l_oPainter.end();
    }
    

    My app is a 64bits C++ Windows 7 program running with Qt 5.2.1 (I use Visual Studio 2012 as dev env, not Qt Creator). I first realized that on the Prod machine, no printer was installed. So I installed a random laser one, and even PDFCreator. But nothing changed.

    Then I realized that QPrinterInfo::availablePrinters() returned an empty list on the Prod machine, while it returned all the actually available printers on my machine. I searched on forums and found that I was missing printsupport/windowsprintersupport.dll in my application folder. So I added it and now the returned printers list is fine, but the problem is not solved : I still get "false" returned from the begin() method.

    I checked the dependencies : nothing to declare. I have Qt5PrintSupport.dll correctly used. No more dll missing, or at least, nothing is telling me the opposite.

    Any idea anyone?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      euchkatzl
      wrote on last edited by
      #2

      I think thats a dependency problem, anyhow.

      Are you using windeployqt.exe tool ?

      If not look here : http://doc.qt.io/qt-5/windows-deployment.html

      To check wether there are dlls missing you can use DependencyWalker : http://www.dependencywalker.com/

      P 1 Reply Last reply
      0
      • E euchkatzl

        I think thats a dependency problem, anyhow.

        Are you using windeployqt.exe tool ?

        If not look here : http://doc.qt.io/qt-5/windows-deployment.html

        To check wether there are dlls missing you can use DependencyWalker : http://www.dependencywalker.com/

        P Offline
        P Offline
        PierreFIL
        wrote on last edited by PierreFIL
        #3

        @euchkatzl

        Thansk, I am not using windeployqt.exe, I am gonna have a look.

        Anyway I do use DependencyWalker, and that's the problem : it doesn't give me any wrong feedback, all is green...

        I have even tried to copy all the Qt dlls into my app folder (hardcore attempt when you suspect that you are missing a dll), but nothing changed.

        raven-worxR 1 Reply Last reply
        0
        • P PierreFIL

          @euchkatzl

          Thansk, I am not using windeployqt.exe, I am gonna have a look.

          Anyway I do use DependencyWalker, and that's the problem : it doesn't give me any wrong feedback, all is green...

          I have even tried to copy all the Qt dlls into my app folder (hardcore attempt when you suspect that you are missing a dll), but nothing changed.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @PierreFIL
          make sure the printer plugins are found and successfully loaded.
          Set QT_DEBUG_PLUGINS env variable to a non-zero and check the console output.
          Note: plugins are searched in special-named folders.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          P 1 Reply Last reply
          1
          • raven-worxR raven-worx

            @PierreFIL
            make sure the printer plugins are found and successfully loaded.
            Set QT_DEBUG_PLUGINS env variable to a non-zero and check the console output.
            Note: plugins are searched in special-named folders.

            P Offline
            P Offline
            PierreFIL
            wrote on last edited by PierreFIL
            #5

            @raven-worx

            The only plugin that seems to be used is windowsprintersupport.dll, and it's correctly loaded from the special-named folder "printsupport"

            1 Reply Last reply
            0
            • E Offline
              E Offline
              euchkatzl
              wrote on last edited by
              #6

              I dont think this a QPrinter problem but more a QPainter problem.

              As a notice you don't need any printers to be installed on your prod machine.
              You want to write to an PDF file and not print the resulting document. Is this right ?

              Try deploying the imageformats that windeployqt.exe gives you.

              P 1 Reply Last reply
              0
              • E euchkatzl

                I dont think this a QPrinter problem but more a QPainter problem.

                As a notice you don't need any printers to be installed on your prod machine.
                You want to write to an PDF file and not print the resulting document. Is this right ?

                Try deploying the imageformats that windeployqt.exe gives you.

                P Offline
                P Offline
                PierreFIL
                wrote on last edited by
                #7

                @euchkatzl

                Correct, this is what I want it to do.

                I tried to use the deploying tool, so I got imageformats dlls + other files added ( some files.qm, D3Dcompiler46.dll, accessible and iconengines folders containing other dlls...), but it doesn't solve the problem.

                K 1 Reply Last reply
                0
                • P Offline
                  P Offline
                  PierreFIL
                  wrote on last edited by
                  #8

                  I found part of the problem :

                  Executing the application with user Windows session fails, BUT executing it with admin session works...

                  Now I have to understand why, and how to fix that. Looks like the lambda user session can't access any printer from Qt.

                  1 Reply Last reply
                  0
                  • P PierreFIL

                    @euchkatzl

                    Correct, this is what I want it to do.

                    I tried to use the deploying tool, so I got imageformats dlls + other files added ( some files.qm, D3Dcompiler46.dll, accessible and iconengines folders containing other dlls...), but it doesn't solve the problem.

                    K Offline
                    K Offline
                    kenchan
                    wrote on last edited by kenchan
                    #9

                    @PierreFIL

                    When I do this I use code like this...

                    printer->newPage();
                    QPainter l_oPainter(&l_oPrinter);
                    
                    ui.wdg_All->render(...);
                    

                    I think the newPage() line would also work just before the call to render.
                    Painter and printer then goes out of scope in my code. How about yours, does this not work for you?

                    P 1 Reply Last reply
                    0
                    • K kenchan

                      @PierreFIL

                      When I do this I use code like this...

                      printer->newPage();
                      QPainter l_oPainter(&l_oPrinter);
                      
                      ui.wdg_All->render(...);
                      

                      I think the newPage() line would also work just before the call to render.
                      Painter and printer then goes out of scope in my code. How about yours, does this not work for you?

                      P Offline
                      P Offline
                      PierreFIL
                      wrote on last edited by
                      #10

                      @kenchan

                      It works too yes, but I don't think it's related to newPage() method

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        PierreFIL
                        wrote on last edited by
                        #11

                        OK, so now that I have launched the program with admin rights and came back with user session, the application is working (?!?)

                        So it was neither a DLL or plugins problem, but just a weird right access blocking. I am sad I can't explain why I had to launch it once with admin session, but at least I am glad I solved my problem.

                        Thanks anyway to those who give their time to help.

                        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