Results 1 to 9 of 9

Thread: How to print textDocument on virtual printer?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    7
    Thanks
    2

    Default How to print textDocument on virtual printer?

    Unfortunately I don't have physical printer on my machine at the moment, so I use PDFCreator virtual printer (http://www.pdfforge.org/products/pdfcreator). This makes it easy to test my printing application, but there are some problems unhappy

    Order Form application from the set of standard Qt examples prints all its documents normal, but my application fails for some reason.

    Here is source code of my application:

    Qt Code:
    1. #include <QApplication>
    2. #include <QPainter>
    3. #include <QPrintDialog>
    4. #include <QPrinter>
    5. #include <QTextDocument>
    6. #include <QTimer>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication app(argc, argv);
    11.  
    12. QPrinter printer;
    13. QPainter painter(&printer);
    14.  
    15. //QPrintDialog *dialog = new QPrintDialog(&printer);
    16. //dialog->setWindowTitle("Print Document");
    17. //if (dialog->exec() != QDialog::Accepted)
    18. // return 0;
    19.  
    20. QTextDocument textDocument;
    21. textDocument.setPlainText("hello");
    22. textDocument.print(&printer);
    23.  
    24. QTimer::singleShot(0, &app, SLOT(quit()));
    25. return app.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 

    If I compile application with comments PDFCreate prints a blank page (without "hello" text). If I show QPrintDialog for setting by uncommenting four lines then nothing happens (even printing a blank page doesn't occur).

    What is wrong? Thanks!

    Qt 4.3.3
    Windows XP SP2
    Last edited by wysota; 17th January 2008 at 12:28. Reason: missing [code] tags

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
  •  
Qt is a trademark of The Qt Company.