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 crash application
Forum Updated to NodeBB v4.3 + New Features

QPrinter crash application

Scheduled Pinned Locked Moved General and Desktop
18 Posts 4 Posters 7.3k Views 1 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.
  • A Offline
    A Offline
    alex_malyu
    wrote on last edited by
    #6

    I think documentation is clear that you should not call setPaperSize
    if that size is not supported by printer.
    The result is undefined

    1 Reply Last reply
    0
    • B Offline
      B Offline
      brcontainer
      wrote on last edited by
      #7

      alex_malyu I am not able to understand what you mean. Could be clearer? You mean the problem is the printer that is causing the "Crash"?

      SGaist: https://bugreports.qt.io/browse/QTBUG-43877

      QT project: https://github.com/brcontainer/qt-helper

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

        @ alex_malyu I was referring at this "setPageSize":http://doc.qt.io/qt-5/qprinter.html#setPageSize using QPageSize

        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
        • B Offline
          B Offline
          brcontainer
          wrote on last edited by
          #9

          Hi alex_malyu,

          If I using like this:

          @QPrintPreviewDialog preview;
          connect(&preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(request(QPrinter*)));
          preview.exec();@

          "work", but don't show text in preview and if click in "Page Setup Button" application crash too:

          !http://i57.tinypic.com/16jituf.png(crash qt printer)!

          QT project: https://github.com/brcontainer/qt-helper

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SuperFun
            wrote on last edited by
            #10

            Hi Guilherme,

            I'm having a similar, if not the same, problem.

            As of Qt 5.4 there are a lot of functions, arguments, and enums with similar-sounding names. These two functions are obsolete:

            @void QPrinter::​setPageSize(PageSize newPageSize)
            void QPrinter::​setPaperSize(PaperSize newPaperSize)@

            The recommended function to use is:

            @bool QPrinter::​setPageSize(const QPageSize & pageSize)@

            You could use it like this:

            @printer.setPageSize(QPageSize(QPageSize::A4));@

            I've been doing it that way and occasionally a customer will have a crash there. The common factor seems to be HP printers. What is your default printer on the computer that's crashing?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              brcontainer
              wrote on last edited by
              #11

              If you had to read the problem occurs in various situations
              Eg.: if click in “Page Setup Button” application crash too.

              I can say that the problem was with the default printer that was problem in driver (actually the "COM"), deleted the door and the problem stopped. But the point is that it should have a system with "QObjectconnect" to detect the failure, since the windows the "QT" uses "createDC": @https://msdn.microsoft.com/en-us/library/windows/desktop/dd183490(v=vs.85).aspx@

              So the problem is not with no deprecated method (see that in my second post I also used the correct method) but with the method "CreateDC".

              Read this:
              @
              QWin32PrintEngine::initialize: CreateDC failed ()
              QWin32PrintEngine::initialize: CreateDC failed ()@

              These errors appear before calling any method.

              QT project: https://github.com/brcontainer/qt-helper

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SuperFun
                wrote on last edited by
                #12

                Just this afternoon I tracked down a similar printing problem that a customer was having. The problem originates in QWin32PrintEnginePrivate::initialize(), the same function that generates the warning message you're getting: "CreateDC failed."

                The problem is that, for some printers, the PRINTER_INFO_2 structure that GetPrinter() returns can have a value of NULL for the pDevMode member. Elsewhere in Qt code it is assumed that pDevMode is not NULL and it is dereferenced causing a crash.

                One of those places is QPrinter::setPageSize(). Another is QPageSetupDialog::exec(). These are two places where your program is crashing.

                Here's a test program you can run (make sure the problem printer is the default printer). This test program uses that same win32 calls that Qt uses but doesn't use Qt for the printing. So you can use this to see if pDevMode is NULL. If it is, then I think my fix will work for both of us.

                @// Win32PrintTest.h

                #ifndef WIN32PRINTTEST_H
                #define WIN32PRINTTEST_H

                #include <QString>
                #include "Windows.h"

                // Run the print test <--- This is the function you should call
                void win32PrintTest();

                // HELPER FUNCTIONS
                // Converts a win32 printer status to a string (PRINTER_STATUS_*)
                QString win32PrinterStatusToString(DWORD status);

                // Converts a win32 paper orientation to a string
                QString win32OrientationToString(short orientation);

                // Converts a win32 paper size to string
                QString win32PaperSizeToString(short paperSize);

                // Converts a win32 print quality to string
                QString win32PrintQualityToString(short printQuality);

                // Converts a win32 duplex option to string
                QString win32DuplexSettingToString(short duplex);

                // Converts a win32 default paper source to string
                QString win32DefaultSourceToString(short source);

                #endif // WIN32PRINTTEST_H
                @

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SuperFun
                  wrote on last edited by
                  #13

                  Ugh this character limit is killing me. Let me upload these files somewhere.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SuperFun
                    wrote on last edited by
                    #14

                    Ok, "here is the header file":http://pastebin.com/57G1kgpF for the test code.

                    And "here is the implementation":http://pastebin.com/Cgh1U3tT

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

                      Hi,

                      Did you took a look at the "bug report system":http://bugreports.qt.io ? There might already be a bug about it and your input would be valuable.

                      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
                      • S Offline
                        S Offline
                        SuperFun
                        wrote on last edited by
                        #16

                        Yes I should have checked before I created "this bug report.":https://bugreports.qt.io/browse/QTBUG-44349

                        Checking now it look's like there's a few old reports. Is it good etiquette to comment on those like "This is probably related and I think I have a fix."?

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

                          If you have a fix and would like to contribute it, just go ahead. Submit your patch to gerrit for code review and include the related bugs in the commit message

                          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
                          • B Offline
                            B Offline
                            brcontainer
                            wrote on last edited by
                            #18

                            Related: https://bugreports.qt.io/browse/QTBUG-43877

                            QT project: https://github.com/brcontainer/qt-helper

                            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