I have a problem when calling Qwidget::render() on a specific printer connected via a network to a PC running XP. I am quite new to using the Qprinter class so I apologise if I am missing something obvious. I get a repeatable crash when rendering to the printer in question. The only diffreence I can see between the working printers and the crashing one is the printer resolution. I seem to get the problem no matter what I render. The crash always seesm to occur at the render() call.

Here is attached example code:

Qt Code:
  1. void MainWindow::menuPrintTest(){
  2. double xscale; double yscale; double scale;
  3. double printerWidth ; double printerHeight ;
  4. double widgetWidth; double widgetHeight ;
  5. QFont printFont("courier", 16);
  6. printFont.setFixedPitch(TRUE);
  7. QTextEdit *qteTestPrintRequest = new QTextEdit("",w);
  8. qteTestPrintRequest ->setFont(printFont );
  9. qteTestPrintRequest ->setFixedHeight(1750);
  10. qteTestPrintRequest ->setFixedWidth(1050);
  11. widgetWidth = qteTestPrintRequest ->width();
  12. widgetHeight = qteTestPrintRequest ->height();
  13.  
  14. QString qsConcat = "Test Printout For Checking XP Print Request Bug\n";
  15. for (int i=0; i<30; i++){ qsConcat+= "Test Printout for Checking XP Print Request Bug\n" ; }
  16. qteTestPrintRequest->append( qsConcat );
  17.  
  18. QPrinter printer(QPrinter::HighResolution);
  19. QString docName = "Test Plot";
  20. if ( !docName.isEmpty()) {
  21. docName.replace (QRegExp (QString::fromLatin1 ("\n")), tr (" -- "));
  22. printer.setDocName (docName);
  23. }
  24. QPrintDialog dialog(&printer);
  25. if ( dialog.exec() ) {
  26. {
  27. {
  28. QPainter painter(&printer);
  29. printerWidth = printer.pageRect().width();
  30. printerHeight = printer.pageRect().height();
  31. xscale = printerWidth/(widgetWidth);
  32. yscale = printerHeight/(widgetHeight);
  33. scale = qMin(xscale, yscale);
  34. painter.scale(scale, scale);
  35. qteTestPrintRequest ->render(&painter);
  36. }
  37. }
  38. }
  39. }
To copy to clipboard, switch view to plain text mode 





The qDebug() output for the scaling is as follows:

printerWidth = 4908.0
printerHeight = 6408.0
widgetWidth = 1050.0
widgetHeight = 1750.0
xscale = 4.674
yscale = 3.662
scale = 3.662

As a matter of interest the output on one of the working printers is

printerWidth = 4760.0
printerHeight = 6814.0
widgetWidth = 1050.0
widgetHeight = 1750.0
xscale = 4.533
yscale = 3.894
scale = 3.894