[Qt-interest] [Qt-interst] QPrintDialog and CoInitializeEx don't mix well

Meißner, Joachim [Rohmann GmbH] meissner at rohmann.de
Wed Nov 3 11:05:09 CET 2010


Hallo all,

 

I have problems creating a QPrintDialog on Windows7 after I have called CoInitializeEx(0,0). The application crashes when exec of the dialog will be called, specifically it crashes when QPrintDialog::exec wants to call PrintDlgEx.

 

Thanks in advance.

 

Yours Joachim 'Jom' Meißner

 

PS:

Here is a small sample program, that creates the behavior described above:

 

Header:

#ifndef __TESTMAIN__HPP__

#define __TESTMAIN__HPP__

 

#include <QWidget>

 

class MyWindow : public QWidget

{

    Q_OBJECT;

public:

    MyWindow( QWidget* p = 0 );

 

    void paintTo( QPainter& painter, QSize s );

 

public slots:

    void print();

};

 

#endif // __TESTMAIN__HPP__

 

Source:

#include <QApplication>

#include <QPrintDialog>

#include <QPrinter>

#include <QPainter>

#include <QPushButton>

 

#include "main.hpp"

 

#include <objbase.h>

 

MyWindow::MyWindow(QWidget * p)

: QWidget( p )

{

    QPushButton* pb = new QPushButton( "print 1", this );

    connect( pb, SIGNAL( clicked() ), this, SLOT( print() ) );

    pb->setGeometry( 10, 10, 100, 30 );

}

 

void MyWindow::paintTo( QPainter& painter, QSize s )

{

    painter.drawText( s.width() / 2, s.height() / 2, "Hallo" );

}

 

void MyWindow::print()

{

    QPrinter printer;

    QPrintDialog pd( &printer, this );

    if ( pd.exec() == QDialog::Accepted )

    {

        QPainter painter( &printer );

        painter.drawText( 100, 100, "Hallo" );

        paintTo( painter, QSize( 500, 500 ) );

    }

}

 

int main( int argc, char** argv )

{

    CoInitializeEx(0,0);

    QApplication app( argc, argv );

    MyWindow w( 0 );

    w.show();

    int rv = app.exec();

    CoUninitialize();

    return rv;

}

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101103/ccc17730/attachment.html 


More information about the Qt-interest-old mailing list