I use a QPrintDialog to initialize a QPrinter object like this:
QPrinter printer;
QPrintDialog dlg(&printer);
if (dlg.exec() == QDialog::Accepted)
{
/* Are we printing to PDF? */
}
On Windows, it's easy to detect if the output is going to a file or to a PDF writer. On a Mac, none of the same functions work:
if ((printer.outputFormat() == QPrinter::PdfFormat)
|| (!printer.outputFileName().isEmpty()))
{
qDebug("PDF mode");
}
Looking at a copy of qprintdialog_mac.mm online, in the function QPrintDialogPrivate::closeCarbonPrintPanel(), Qt attempts to detect if the output is redirected to a file. It stores the file name in a member of QMacPrintEnginePrivate. Somehow that name never makes its way to the QPrinter object. I'm not sure where the disconnect is.
So..... how can I tell if the print output is actually going to a file? I'm willing to get platform specific here if it's easy. I have zero Mac programming experience though.