首页 > 解决方案 > Qt:使用 QPainter::begin() 处理“将打印输出另存为”对话框

问题描述

这是我的问题的最小可重现示例:

#include <QCoreApplication>
#include <QtPrintSupport/QPrinter>
#include <QPainter>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QPrinter printer;
    QPainter painter;

    // this will open a file dialog to save a pdf file
    if (!painter.begin(&printer)) {
        qDebug() << "how to get the difference between 'Dialog Canceled' and 'File in use' here?";

    }
    else {
        //do the painting stuf...
    }

    return a.exec();
}

我的问题是 - 正如代码中已经提到的 - 我如何知道对话框是否被用户取消或 pdf 文件正在使用中(例如在 Adob​​e Reader 中打开)?

我已经尝试检查printer.outputFormat()and theprinter.docName()但它们都是空的。

标签: qtpdfqpainterqprinter

解决方案


推荐阅读