The linked thread doesn't pertain to Qt4, but I think I've found a work-around (on WinXP Home with Qt 4.2.1 at least). You still need to use QPrintDialog, but you don't need to actually display it..
document.setHtml("testing");
printer.setPrinterName("desired printer name here");
document.print(&printer);
QTextDocument document;
document.setHtml("testing");
QPrinter printer;
printer.setPrinterName("desired printer name here");
QPrintDialog dialog(&printer, this);
document.print(&printer);
To copy to clipboard, switch view to plain text mode
If I omit the setPrinterName call, I get output to the default printer.
I've also noticed that if I try to print to "Generic / Text Only", I get nothing in the resulting file except for CR's and LF's. The supplied code gives me 1 CR and 50 LFs. The output is the same even if I add
if (dialog.
exec() == QDialog::Accepted)
if (dialog.exec() == QDialog::Accepted)
To copy to clipboard, switch view to plain text mode
before the document.print
Bookmarks