PDA

View Full Version : Printing via QPrinter doesnt work



mSergey
16th January 2008, 17:42
I'm trying to print some plain text in my small console application (which is listed below), but it doesnt work properly. When application starts, I see this error message:

QPainter::begin(): Returned false

... and then nothing happens.

I didn't find any useful with Google unhappy

I'm using Qt 4.3.3 under Windows XP SP2

Standard "Rich Text/Order Form" example prints documents finely, but I don't know why it doesnt work in my program.

Wherein can be the problem?

Thanks.

Source:


#include <QCoreApplication>

#include <QPainter>
#include <QPrinter>
#include <QTextDocument>
#include <QTimer>

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

QPrinter printer;
QPainter painter(&printer);

QTextDocument textDocument;
textDocument.setPlainText(QString("some text"));
textDocument.print(&printer);

QTimer::singleShot(0, &app, SLOT(quit()));
return app.exec();
}

jacek
16th January 2008, 19:00
Use QApplication instead of QCoreApplication.