PDA

View Full Version : QPainter problem with real printer on linux



corossig
22nd February 2012, 14:47
Hello,
I want to print line and text on a real printer but this doesn't work all the time, but on fake printer(screen, PDF and PS) this work.



MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent){
QPushButton *b = new QPushButton("Print", this);
setCentralWidget(b);
connect(b, SIGNAL(clicked()), this, SLOT(onPrint()));
}

void
MainWindow::onPrint(){
QPrinter p;
QPrintDialog dialog(&p, this);
if(dialog.exec() == QDialog::Accepted){
QPainter *painter = new QPainter(&p);
painter->drawLine(0,0,0,100);
delete painter;
}
}


This piece of code doesn't work all time, sometimes CUPS tell me that job is cancelled, sometimes a line is draw.
Is that someone already had this problem?

If I put "sleep(1);" before delete painter this piece of code works. Complex printing (SvgRenderer and QTextDocument) works too.

Configuration:
-Archlinux up-date
-Qt 4.8.0
-Cups 1.5.0 usblp