PDA

View Full Version : QPrinter and QPainter do not print to local printer under Windows (QT4)



derda17
26th October 2016, 08:49
Hi,

I'm having some troubles with printing under Windows. I'm setting a qprinter via a qprintdialog and pass the qprinter to a method which creates a qpainter on the qprinter. Essentially:



void functionA()
{
QPrinter printer;
printer.setColorMode( QPrinter::Color );
printer.setOrientation( QPrinter::Landscape );
QPrintDialog printDialog( &printer, this );
if ( printDialog.exec() != QDialog::Accepted )
return;
print( printer );
}

void print( QPrinter &printer )
{
printer.setOutputFormat( QPrinter::PdfFormat );
printer.setPaperSize( _gttPrintDialog->pdfPaperSize() );
printer.setFullPage( true );
QPainter painter( &printer );
// ...work with the painter...
}


This results in no printout under Windows but under Linux there are no problems. Additionally, as soon as I define the printer inside print(...) everything works like a charm. Sadly, this is no permanent option and it seems like QPrinter can neither be passed by value nor can be copied to a local variable.
What's the reason for this behavior under Windows and is there any solution simpler than passing qpainters instead of qprinters and restructer the whole call tree of paint(...)?

anda_skoa
26th October 2016, 11:44
I doubt this has anything to do with passing the printer by reference, but you could try passing it by pointer.

Cheers,
_