PDA

View Full Version : I can't print...



brevleq
17th January 2008, 13:02
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:



void Visualizador::imprimir(void){
defDocumento();
QPrintDialog telaImprimir(&printer,this);
if(telaImprimir.exec()){
QPainter painter(&printer);
relatorio.print(&printer);
}
}


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

jpn
18th January 2008, 16:54
What if you create the QPrinter object in Visualizador::imprimir()?

Edit: Or is the problem exactly the same than in this thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-printing-via-qprinter-doesnt-work-11314.html)?

brevleq
19th January 2008, 01:26
The same error occurs!!

anonyme_84
20th January 2008, 17:57
Hi,
I think you must remove the following line because your printer is busy by the QPainter.



QPainter painter(&printer);


So... your code looks like this :



void Visualizador::imprimir(void){
defDocumento();
QPrintDialog telaImprimir(&printer,this);
if(telaImprimir.exec()){
relatorio.print(&printer);
}
}

brevleq
22nd January 2008, 11:06
Thanks!!
Now I can print well, but I didn't understand why simply removing that line we solved the problem? Could you explain me?

jpn
22nd January 2008, 11:13
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.