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()printer.docName(),但它们都是空的。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...