[Qt-interest] QPrinter, QPainter and low-level CUPS calls?

Srdjan Todorovic todorovic.s at googlemail.com
Wed Dec 2 19:32:46 CET 2009


Hi everyone,

Is it possible to use QPrinter and QPainter (Qt-4.x) to paint some
data (text, barcode etc) but to use CUPS low-level calls to select the
printer?

Basically I have a problem in that the only way to select which
printer to print to, is to use QPrintDialog, and the user does not
want to even see any dialogs at all. The painter should print direclty
to the default printer without any prompting.

I have managed to enumerate printers using low-level CUPS calls, but I
can't see a way to use Qt's print/painting system on an already
selected printer instance (similar to
http://doc.trolltech.com/4.2/qabstractsocket.html#setSocketDescriptor
where you can create a socket from low-level calls and then merge the
socket with a QSocket).

I have tried to print to PDF file and then use lpr -P printer file.pdf
but this produces output that is very badly formatted (I'm printing on
4 by 6 inch labels and *have* to have exact layouts on paper output).

I have tried to show()/accept()/exec() + singleShot timer to close the
QPrintDialog so that I very quickly hide it or close it, but nothing
seems to be sent to the printer in that case, as if the printer is not
valid.

Something like QCUPSSupport could be useful, but it seems to be private in Qt.

Any ideas?

Thanks
Srdjan



More information about the Qt-interest-old mailing list