Results 1 to 2 of 2

Thread: QPrinter and QPainter do not print to local printer under Windows (QT4)

  1. #1
    Join Date
    Apr 2016
    Qt products
    Unix/X11 Windows

    Question QPrinter and QPainter do not print to local printer under Windows (QT4)


    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:
    Qt Code:
    1. void functionA()
    2. {
    3. QPrinter printer;
    4. printer.setColorMode( QPrinter::Color );
    5. printer.setOrientation( QPrinter::Landscape );
    6. QPrintDialog printDialog( &printer, this );
    7. if ( printDialog.exec() != QDialog::Accepted )
    8. return;
    9. print( printer );
    10. }
    12. void print( QPrinter &printer )
    13. {
    14. printer.setOutputFormat( QPrinter::PdfFormat );
    15. printer.setPaperSize( _gttPrintDialog->pdfPaperSize() );
    16. printer.setFullPage( true );
    17. QPainter painter( &printer );
    18. // with the painter...
    19. }
    To copy to clipboard, switch view to plain text mode 

    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(...)?

  2. #2
    Join Date
    Jan 2006
    Graz, Austria
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Unix/X11 Windows

    Default Re: QPrinter and QPainter do not print to local printer under Windows (QT4)

    I doubt this has anything to do with passing the printer by reference, but you could try passing it by pointer.


Similar Threads

  1. How to print pdf file on Printer in windows
    By lekhrajdeshmukh in forum Qt Programming
    Replies: 9
    Last Post: 30th November 2011, 16:36
  2. read out local printer
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2011, 19:15
  3. Replies: 1
    Last Post: 9th November 2009, 09:27
  4. Replies: 5
    Last Post: 15th January 2009, 09:03
  5. Replies: 4
    Last Post: 18th December 2007, 08:31

Tags for this Thread


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.