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

时间:2014-12-03 23:06:52

标签: c++ qt printing cups

有没有办法使用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 ***

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

1 个答案:

答案 0 :(得分:1)

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

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

PrinterState QPrinter::printerState() const

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