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

QPrinter crash application

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

    Setting "setPaperSize" crash application and show this message in console:

    bq. QWin32PrintEngine::initialize: CreateDC failed ()
    QWin32PrintEngine::initialize: CreateDC failed ()
    Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly

    example:

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    QObject::connect(ui->printButton, SIGNAL(clicked()), this, SLOT(printAction()));
    }

    void MainWindow::printAction() {
    QPrinter p;
    p.setPaperSize(QPrinter::A4);//Crash application
    }@

    Without "setPaperSize" work fine, but using "QPrintPreviewDialog" and click in "Page setup" button, application crash too and show this error (same error):

    bq. QWin32PrintEngine::initialize: CreateDC failed ()
    QWin32PrintEngine::initialize: CreateDC failed ()
    Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly

    perhaps the error occurs for the same reason.

    Image (Page setup button):

    !http://i57.tinypic.com/16jituf.png(qt5 page setup)!

    Is it a bug or I did something wrong?

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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      from Qt documentation:

      void QPrinter::setPaperSize ( PaperSize newPaperSize )
      Sets the printer paper size to newPaperSize if that size is supported. The result is undefined if newPaperSize is not supported.

      The default paper size is driver-dependent.

      This function is useful mostly for setting a default value that the user can override in the print dialog.

      This function was introduced in Qt 4.4.

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

        Hi,

        This function has been obsoleted, you should rather use the new setPageSize

        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
          #4

          [quote author="SGaist" date="1421357569"]Hi,

          This function has been obsoleted, you should rather use the new setPageSize[/quote]

          In docs ( http://qt-project.org/doc/qt-4.8/qprinter-obsolete.html ) setPageSize is obsolete:

          bq. void QPrinter::setPageSize ( PageSize newPageSize )

          Sets the printer page size based on newPageSize.

          Use setPaperSize() instead.

          But I tried, and "p.setPageSize(QPrinter::A4);" crash too.

          Example:

          @ QPrinter p;
          qDebug() << 1;
          p.setResolution(300);
          qDebug() << 2;
          p.setOrientation(QPrinter::Portrait);
          qDebug() << 3;
          p.setPageSize(QPrinter::A4);

          QPrintPreviewDialog preview(&p);
          qDebug() << 5;
          connect(&preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(request(QPrinter*)));
          qDebug() << 6;
          preview.exec&#40;&#41;;
          qDebug(&#41; << 7;@
          

          Return this:

          bq. QWin32PrintEngine::initialize: CreateDC failed ()
          QWin32PrintEngine::initialize: CreateDC failed ()
          1
          2
          3
          Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly

          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
            #5

            Then you may have found a bug, you should check the "bug report system":http://bugreports.qt.io to see if it's something known. If not please consider opening a report with a minimal compilable example and as much details as possible about your setup (OS, printer type, driver version etc.)

            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
            • 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