2

Is there a way to detect if a printer is online using libcups or Qt?

I am working on a program that requires a printer, and uses both libcups and QPrinter

I would like to give the user a nice error message if the current/default printer is not connected.

Right now, if the default printer is turned off (or not connected),

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

this crashes:

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

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

Thalia
  • 13,637
  • 22
  • 96
  • 190

1 Answers1

1

There is no accurate way to detect the state of printer as some printers don't have the capability of reporting their state to the operating system.

Never the less you can get the current state of the printer by :

PrinterState QPrinter::printerState() const

Which returns Idle, Active, Aborted and Error. You can check if the printer state is Active or Idle. But there is no guarantee that your printer reports it's state correctly.

Nejat
  • 31,784
  • 12
  • 106
  • 138
  • I have noticed for many printers, the status is "Idle" ... But for the custom printer i have to use preferentially, when the physical printer is off, in print properties I see "Idle - Connected to printer." (which is the last state it saw I guess) - I tried printing a test page from printer properties and got "Processing - The printer is unreachable at this time." .... After turning it on, the state did not change until I sent a test page again. It seems it remembers its last state, so I would need to perform some action to check its real state..... – Thalia Dec 04 '14 at 15:16
  • Accepting this but I will have to find a way to send some sort of "ping" to the printer before I check state, because the state is generally reported as of last action... and it is likely the printer was turned off since. – Thalia Dec 09 '14 at 15:11