QPrintDialog.exec() crash



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



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



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



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



  • 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



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



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



  • 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";
        }
    }
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.