Qt Forum

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

    QPrinter crash application

    General and Desktop
    4
    18
    6239
    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.
    • B
      brcontainer last edited by

      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 Reply Quote 0
      • A
        alex_malyu last edited by

        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 Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 0
          • B
            brcontainer last edited by

            [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 Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              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 Reply Quote 0
              • A
                alex_malyu last edited by

                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 Reply Quote 0
                • B
                  brcontainer last edited by

                  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 Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    @ 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 Reply Quote 0
                    • B
                      brcontainer last edited by

                      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 Reply Quote 0
                      • S
                        SuperFun last edited by

                        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 Reply Quote 0
                        • B
                          brcontainer last edited by

                          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 Reply Quote 0
                          • S
                            SuperFun last edited by

                            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 Reply Quote 0
                            • S
                              SuperFun last edited by

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

                              1 Reply Last reply Reply Quote 0
                              • S
                                SuperFun last edited by

                                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 Reply Quote 0
                                • SGaist
                                  SGaist Lifetime Qt Champion last edited by

                                  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 Reply Quote 0
                                  • S
                                    SuperFun last edited by

                                    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 Reply Quote 0
                                    • SGaist
                                      SGaist Lifetime Qt Champion last edited by

                                      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 Reply Quote 0
                                      • B
                                        brcontainer last edited by

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

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

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