Results 1 to 6 of 6

Thread: I can't print...

  1. #1
    Join Date
    Aug 2007
    Posts
    64
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy I can't print...

    I'm having a problem to print a QTextDocument!!
    When I set the "print to file" checkbox in QPrintDialog, no problem! The file is correctly saved in disk, but when I try print, this message appears in konsole:

    QPainter::begin(): Returned false

    This the method I'm using to print:

    Qt Code:
    1. void Visualizador::imprimir(void){
    2. defDocumento();
    3. QPrintDialog telaImprimir(&printer,this);
    4. if(telaImprimir.exec()){
    5. QPainter painter(&printer);
    6. relatorio.print(&printer);
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    The var relatorio is a QTextDocument and the text was setted in defDocumento()!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: I can't print...

    What if you create the QPrinter object in Visualizador::imprimir()?

    Edit: Or is the problem exactly the same than in this thread?
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Posts
    64
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I can't print...

    The same error occurs!!

  4. #4
    Join Date
    Oct 2007
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: I can't print...

    Hi,
    I think you must remove the following line because your printer is busy by the QPainter.

    Qt Code:
    1. QPainter painter(&printer);
    To copy to clipboard, switch view to plain text mode 

    So... your code looks like this :

    Qt Code:
    1. void Visualizador::imprimir(void){
    2. defDocumento();
    3. QPrintDialog telaImprimir(&printer,this);
    4. if(telaImprimir.exec()){
    5. relatorio.print(&printer);
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 
    anonyme_84

  5. #5
    Join Date
    Aug 2007
    Posts
    64
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I can't print...

    Thanks!!
    Now I can print well, but I didn't understand why simply removing that line we solved the problem? Could you explain me?

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: I can't print...

    As he said, the printer was busy. You can't open multiple painters on a single paint device. You were opening a QPainter on the printer before passing it to QTextDocument::print() which was then unable to open its own QPainter on the printer.
    J-P Nurmi

Similar Threads

  1. how to print an html file?
    By patcito in forum Qt Programming
    Replies: 5
    Last Post: 31st August 2008, 16:50
  2. Print html on fixed size
    By mamyte03@gmail.com in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2007, 10:33
  3. Print QStandardItemModel
    By Mrdata in forum Newbie
    Replies: 1
    Last Post: 4th July 2007, 23:14
  4. print QTableWidget
    By chak_med in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 18:46
  5. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44

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.