【问题标题】:Qt - Simple code QPrinter doesn't work on others pcQt - 简单代码 QPrinter 在其他电脑上不起作用
【发布时间】:2015-07-09 23:56:08
【问题描述】:
QPrinter printer(QPrinter::HighResolution);         

    printer.setPageSize(QPrinter::A4);
    printer.setOrientation(QPrinter::Portrait);
    printer.setPageMargins (15,15,15,15,QPrinter::Millimeter);
    printer.setFullPage(false);
    printer.setOutputFormat(QPrinter::NativeFormat);                     


    QPainter painter(&printer);                           

    painter.setFont(QFont("Tahoma",8));
    painter.drawText(200,200,"Test prova prova");
    painter.end();

在带有 QT 的 PC 中,打印工作正常(打印工作正常),但在其他 PC(一台使用 win 8.1,一台使用 win 7)中无法启动(打印未启动,打印队列为空) 我不明白为什么,我没有收到任何错误。

我用:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPrinter>
#include <QPainter>

在 .pro 中:

QT += printsupport
QTPLUGIN += windowsprintersupport

dll“Qt5PrintSupport”当然存在于文件夹中。 很抱歉这个菜鸟问题,但我不明白我做错了什么。

【问题讨论】:

  • 您有任何错误吗? “不启动”可以意味着任何事情。
  • 您好,没有错误,只需按下“打印”按钮,打印就没有开始,打印队列是空的。
  • 您的方法在我的机器上运行(Windows 8)。你怎么称呼它?
  • 嗨@demonplus,我用一个简单的void MainWindow::on_Stampa_clicked() {} 用户界面中的按钮调用它。

标签: c++ qt qpainter qprinter


【解决方案1】:

您需要目标机器上的 windowsprintersupport.dll 插件。当您将 Qt 用作 DLL 时,设置 QTPLUGIN 不起作用,只有在将 Qt 静态链接到您的应用程序时才起作用。

【讨论】:

  • 添加{myAppPath}\printsupport\windowsprintersupport.dll 完美运行,非常感谢!
【解决方案2】:

如果您使用的是 CMake 项目,可以使用 Qt5::QWindowPrinterSupportPlugin 配置复制到目标目录。

get_target_property(_loc Qt5::QWindowsPrinterSupportPlugin LOCATION) configure_file(${_loc} Release/printsupport/windowsprintersupport.dll COPYONLY) message("copied file: ${_loc}")

【讨论】:

    猜你喜欢
    • 2018-05-02
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多