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. QPrintDialog.exec() crash

QPrintDialog.exec() crash

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.0k 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.
  • B Offline
    B Offline
    bsikander
    wrote on last edited by
    #1

    I have a legacy application that was written in Visual C++ 2005 using QT. Recently, i have a task to update one of the functionality and i am having some issues in the old functionalities.

    The application prints a form and for printing it tries to open up the print dialog box. But when i call the "exec" function of the QPrintDialog class, the application is crashed. With the following message in the console

    bq. "The requested operation is not supported".
    "A first chance of exception of type 'System.Runtime.InteropServices.SEHException occured in xxxx.exe' "
    "Additional information: External component has thrown an exception".

    Other then that there is no information about the exception. I even tried to write the simplest code and i still have the exception.

    @ QPrintDialog printDialog(printer, parent);
    if (printDialog.exec() == QDialog::Accepted) {
    // print ...
    }@

    Currently my Operating system is Windows 7. The application was developed most probably on Windows XP.

    Any help will be greatly appreciated.

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      The code looks good, but how does your printer look like?? The arguments to give the QPRintDialog might be the cause of the issue.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bsikander
        wrote on last edited by
        #3

        well, i just initialized the printer and passed it to the printDialog and i still gives the error.

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          If you need of help, please post those parts of your program. There might be a mistake in there.

          Greetz, Jeroen

          1 Reply Last reply
          0
          • R Offline
            R Offline
            reta
            wrote on last edited by
            #5

            I have the same issue with a program of mine using Qt 5.3.1, mingw32 4.8.2 on Windows 7.

            @
            qreal seitenRandLinks = 20;
            qreal seitenRandRechts = 10;
            qreal seitenRandOben = 10;
            qreal seitenRandUnten = 10;

            QPrinter drucker(QPrinter::HighResolution);
            if(!drucker.isValid())
            {
                return false;
            }
            
            //if I uncomment the following line, the application would crash here
            //drucker.setPaperSize(QPrinter::A4);
            
            drucker.setOrientation(QPrinter::Portrait);
            
            drucker.setPageMargins(seitenRandLinks, seitenRandOben, seitenRandRechts, seitenRandUnten, QPrinter::Millimeter);
            
            drucker.setFullPage(false);
            
            drucker.setCreator(QString("%1 %2").arg(APP_NAME, APP_VERSION));
            
            drucker.setDocName(x->gibName());
            
            QPrintDialog druckDialog(&drucker, dynamic_cast<QWidget*>(dieGui));
            
            if (druckDialog.exec&#40;&#41; == QDialog::Accepted)
            {
                ...
            }
            

            @

            The application crashes when executing druckDialog.exec()

            Any hints appreciated.

            Holger

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Who is dieGui? Where does it come from? It is the parent, so this might be your MainWindow?

              Greetz, Jeroen

              1 Reply Last reply
              0
              • R Offline
                R Offline
                reta
                wrote on last edited by
                #7

                Sorry for omitting that.

                dieGui is the main window of the application (custom class Gui derived from QMainWindow) and is assigned as the parent of the druckDialog (QPrintDialog).

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  reta
                  wrote on last edited by
                  #8

                  Some further investigation turned out that the QPrintDialog is not (only) the problem.

                  I uncomment the QPrintDialog::exec() line 27 and the programm is running further. The printing actually is done by assembling an HTML-String, putting that into a QTextEdit widget and finally calling the print method of the QTextEdit object.

                  The weird thing is that it doesn't crash on all machines, but only some. So it maybe also have something to do with printer configuration.

                  These line follow the original code-snipet beginning from the uncomment if-statement at line 27.

                  Any help to track this problem down greatly appreciated!

                  @
                  //if (druckDialog.exec() == QDialog::Accepted)
                  {
                  QString html;
                  //fill HTML markup into html:QString

                      QTextEdit* meinTextEdit = new QTextEdit(dieGui);
                  
                      meinTextEdit->setHtml(html);
                  
                      if(drucker.isValid())
                      {
                          meinTextEdit->print(&drucker); //at this line the programm cashes
                      }
                      else
                      {
                          qDebug() << "print invalid";
                      }
                  }
                  

                  @

                  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