PDA

View Full Version : QPrinter in qt4.1.3



~YosogO~
27th August 2007, 09:13
I try to write a simple program to print out a line from a printer.
Following is my code:

QPrinter printer(QPrinter::HighResolution);
QPainter painter(&printer);
painter.setPen(QColor(0,0,0));
painter.drawLine(10,10,100,100);
painter.end();

But somehow, the program crash with error message: Access violation reading location.

Can anyone tell me what's wrong with the code?

marcel
27th August 2007, 09:25
Have you set any page size for the printer?

~YosogO~
27th August 2007, 09:49
Even i set all the print settings, the problem still there.

Following is my settings:

printer.setPageSize(QPrinter::Letter);
printer.setColorMode(QPrinter::GrayScale);
printer.setOrientation(QPrinter::Landscape);
printer.setNumCopies(1);
printer.setFullPage(true);


The problem occured on line : painter.end();

marcel
27th August 2007, 09:57
I think the painter might still be active when you call end(), although it should not crash.
end() is called anyway in the destructor, so there is no need to actually call it manually.