QTextDocument doc; doc.setPlainText("Hello, world!"); doc.print(&printer);
QTextDocument doc; QTextCursor cursor(&doc); cursor.insertHtml("Hello, world!"); doc.print(&printer);This code snippet creates a QTextDocument, inserts rich text content using HTML tags, and prints it to the default printer. The printed output will show "Hello" in bold and "world!" in italics. In summary, QTextDocument is a class in the QtCore library of Qt that can be used to display rich-text documents with various formatting styles. It provides methods for printing text documents to a printer.