QPrinter printer; printer.setDocName("My Document");
QPrinter printer(QPrinter::HighResolution); QPrintDialog dialog(&printer); if (dialog.exec() == QDialog::Accepted) { printer.setDocName("My Document"); // code for printing the document }This example creates a QPrinter object 'printer' with high resolution and creates a printer dialog using QPrintDialog class. When the dialog is accepted, the document name is set as "My Document" for the printer object. Package/library: Qt.