[英]How to get signal in Qt from a printer when it finishes printing?
我试图在Qt中获取打印机的通知,但不幸的是找不到任何解决方案。 我已经尝试检查状态,但是它永远不会改变,它始终是'PrinterState :: Idle'。
void Functions::print(QString fileName)
{
printerTmr = new QTimer(this);
printerTmr->setInterval(2000);
connect(printerTmr, SIGNAL(timeout()), this, SLOT(printerStateCheck()));
printerTmr->start(); //start checking the state of the printer
printer.setPageSize(QPrinter::A6);
printer.setOrientation(QPrinter::Landscape);
QImage img(fileName);
QSize size;
QIcon icon;
QPainter painter( &printer );
int w = printer.pageRect().width();
int h = printer.pageRect().height();
QRect page( 0, 0, w, h );
QImage image(fileName);
if (!image.isNull())
icon.addPixmap(QPixmap::fromImage(image), QIcon::Normal, QIcon::On);
icon = icon;
size = QSize(w,h);
QPixmap pixmap = icon.pixmap(size, QIcon::Normal, QIcon::On);
........
//draw simulated landscape
page.adjust( w/20, h/20, -w/20, -h/20 );
painter.drawPixmap(QPoint(0,0),pixmap);
}
void Functions::printerStateCheck()
{
if(printer.printerState() == QPrinter::PrinterState::Idle){
qDebug()<<"PrinterState::Idle";
}else if(printer.printerState() == QPrinter::PrinterState::Error){
qDebug()<<"PrinterState::Error";
}else if(printer.printerState() == QPrinter::PrinterState::Active){
qDebug()<<"PrinterState::Active";
}else if(printer.printerState() == QPrinter::PrinterState::Aborted){
qDebug()<<"PrinterState::Aborted";
}
}
Qt中的打印可能性非常简单。 QPrinter设备代表一系列打印输出页面,其使用方式与其他绘画设备(例如QWidget和QPixmap)几乎完全相同 。
在Windows或macOS上直接打印到打印机时,QPrinter使用内置的打印机驱动程序。 在X11上, QPrinter使用通用Unix打印系统(CUPS)将PDF输出发送到打印机。
或者,可以使用printProgram()函数来指定要使用的命令或实用程序,而不是系统默认值。 (PS:但仅在X11系统上用于pdf打印)
QPrinter :: printerState()返回打印机的当前状态。 这可能并不总是准确的(例如,如果打印机不具备向操作系统报告其状态的能力)。
因此,就像Qt doc所说的那样,它是在打印机,打印机驱动程序,打印子系统和OS本身上提供状态的。 我认为您比Linux和Windows更有运气在CUPS下打印状态。
尝试直接使用OS打印API。
这是有关如何获取打印机和打印作业状态的 WINAPI示例代码的信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.