Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Detecting a printer connection
Forum Updated to NodeBB v4.3 + New Features

Detecting a printer connection

Scheduled Pinned Locked Moved General and Desktop
6 Posts 6 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kewal
    wrote on last edited by
    #1

    I was trying to find the printer state, though QPrinter provides QPrinter::printerState
    Returns the current state of the printer. This may not always be accurate (for example if the printer doesn't have the capability of reporting its state to the operating system).

    is there any way to monitor the printer when it is connected and disconnected and receive events in the application?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Blizzard
      wrote on last edited by
      #2

      printerState returns the state of the printer, as you said.

      QPrinter::Idle 0
      QPrinter::Active 1
      QPrinter::Aborted 2
      QPrinter::Error 3

      You can just set up a signal that checks if the printer is active or not based on the above chart, which could then trigger your events.

      Software Engineer | Aerospace & Defence

      1 Reply Last reply
      0
      • G Offline
        G Offline
        guru
        wrote on last edited by
        #3

        is this possible to detect a thermal printer?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          bq. is this possible to detect a thermal printer?

          This really goes beyond the scope of Qt. Qt will happily work with any printer that is configured on your system, but I'm not aware of any way to detect the specifics of whether a printer is a thermal printer or not.

          However, if you have a thermal printer configured already, you can print to it from Qt.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mamun
            wrote on last edited by
            #5

            here is the solution for the connection problem,
            int count = 0;
            QList<QPrinterInfo> info_list = QPrinterInfo::availablePrinters();
            foreach ( QPrinterInfo info, info_list )
            {
            count++;
            qDebug()<< "Printer_"<< count<< ": " << info.printerName() << "State: " << info.state();

                    if(info.printerName() == printerName)
                    {
                        if (info.state() == 0)
                            qDebug()<< "Printer Idle";
                        else if (info.state() == 1)
                            qDebug()<< "Printer Active";
                        else if (info.state() == 2)
                            qDebug()<< "Printer Aborted";
                        else if (info.state() == 3)
                            qDebug()<< "Printer Error";
                        else
                            qDebug()<< "Printer Undefined Error";
                    }
            
                }
            
            S 1 Reply Last reply
            1
            • M Mamun

              here is the solution for the connection problem,
              int count = 0;
              QList<QPrinterInfo> info_list = QPrinterInfo::availablePrinters();
              foreach ( QPrinterInfo info, info_list )
              {
              count++;
              qDebug()<< "Printer_"<< count<< ": " << info.printerName() << "State: " << info.state();

                      if(info.printerName() == printerName)
                      {
                          if (info.state() == 0)
                              qDebug()<< "Printer Idle";
                          else if (info.state() == 1)
                              qDebug()<< "Printer Active";
                          else if (info.state() == 2)
                              qDebug()<< "Printer Aborted";
                          else if (info.state() == 3)
                              qDebug()<< "Printer Error";
                          else
                              qDebug()<< "Printer Undefined Error";
                      }
              
                  }
              
              S Offline
              S Offline
              Shivaraj
              wrote on last edited by
              #6

              @Mamun I tried this, my printer is on and connected to laptop but it is showing idle and when I remove it is also idle , thanks for reply.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved