Results 1 to 2 of 2

Thread: Printing via QPrinter doesnt work

  1. #1
    Join Date
    Jan 2008
    Posts
    7
    Thanks
    2

    Default Printing via QPrinter doesnt work

    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:

    Qt Code:
    1. #include <QCoreApplication>
    2.  
    3. #include <QPainter>
    4. #include <QPrinter>
    5. #include <QTextDocument>
    6. #include <QTimer>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QCoreApplication app(argc, argv);
    11.  
    12. QPrinter printer;
    13. QPainter painter(&printer);
    14.  
    15. QTextDocument textDocument;
    16. textDocument.setPlainText(QString("some text"));
    17. textDocument.print(&printer);
    18.  
    19. QTimer::singleShot(0, &app, SLOT(quit()));
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing via QPrinter doesnt work

    Use QApplication instead of QCoreApplication.

  3. The following user says thank you to jacek for this useful post:

    mSergey (17th January 2008)

Similar Threads

  1. QPrinter problems
    By Teuniz in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2007, 08:51
  2. Printing problem in windows
    By joseph in forum Qt Programming
    Replies: 6
    Last Post: 12th July 2007, 08:04
  3. Replies: 0
    Last Post: 28th June 2006, 20:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.