cups:如何确定当前/默认打印机是否已物理连接并打开

cups: How can I determine if the current / default printer is physically connected and turned on?

本文关键字:连接 是否 打印机 何确定 默认 cups      更新时间:2023-10-16

有没有办法使用 libcups 或 Qt 检测打印机是否在线?

我正在开发一个需要打印机的程序,并且同时使用libcups和QPrinter

如果当前/默认打印机未连接,我想给用户一个很好的错误消息。

现在,如果默认打印机已关闭(或未连接(,

cups_dest_s printers = NULL;
int printerCount = cupsGetDests(&printers);

这将崩溃:

*** glibc detected *** /home/me/myApp/myApp: double free or corruption (out): 0x088501e0 ***

如何确定当前/默认打印机是否已物理连接并打开?

没有准确的方法来检测打印机的状态,因为某些打印机无法向操作系统报告其状态。

您可以

通过以下方式获取打印机的当前状态:

PrinterState QPrinter::printerState() const

它返回 IdleActiveAbortedError。您可以检查打印机状态是Active还是Idle。但是不能保证您的打印机正确报告其状态。