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..

Qt Code:
  1. QTextDocument document;
  2. document.setHtml("testing");
  3.  
  4. QPrinter printer;
  5. printer.setPrinterName("desired printer name here");
  6. QPrintDialog dialog(&printer, this);
  7. 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
Qt Code:
  1. if (dialog.exec() == QDialog::Accepted)
To copy to clipboard, switch view to plain text mode 
before the document.print