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. can a QComboBox notify when clicked?
Forum Updated to NodeBB v4.3 + New Features

can a QComboBox notify when clicked?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 5 Posters 16.3k Views 4 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi - I'm using a combo box to give the user a choice of COM ports available. I'd like to update the available list when the user plugs in or unplugs a device, but this probably is fairly difficult (and unnecessary).

    I'd settle for updating the list when the user clicks on the box, but the activated() signal doesn't trigger until a selection is made. Any ideas how I can get notified on a click?

    If the QComboBox isn't the best object for this, I'd welcome alternatives. Thanks...

    C 1 Reply Last reply
    0
    • mzimmersM mzimmers

      Hi - I'm using a combo box to give the user a choice of COM ports available. I'd like to update the available list when the user plugs in or unplugs a device, but this probably is fairly difficult (and unnecessary).

      I'd settle for updating the list when the user clicks on the box, but the activated() signal doesn't trigger until a selection is made. Any ideas how I can get notified on a click?

      If the QComboBox isn't the best object for this, I'd welcome alternatives. Thanks...

      C Offline
      C Offline
      Charlie_Hdz
      wrote on last edited by
      #2

      @mzimmers

      You know, there is a list of signals you can use in QComboBox:
      http://doc.qt.io/qt-5/qcombobox.html

      Anyway I couldn't find a signal that is useful for this case.

      If the QComboBox isn't the best object for this, I'd welcome alternatives. Thanks..

      IMO, I would like to create a function that is called periodically, (QTime) to refresh the list.

      Kind Regards,
      Enrique Hernandez
      gearstech.com.mx
      chernandez@gearstech.com.mx

      1 Reply Last reply
      1
      • Joel BodenmannJ Offline
        Joel BodenmannJ Offline
        Joel Bodenmann
        wrote on last edited by
        #3

        I'd recommend you to create a subclass of QComboBox in which you overwrite QComboBox::showPopup(). It's a virtual function. Just update the list and then call the default implementation.

        Industrial process automation software: https://simulton.com
        Embedded Graphics & GUI library: https://ugfx.io

        1 Reply Last reply
        5
        • mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #4

          @Joel-Bodenmann that sounds like a good approach. Having given this some more thought, though, I'm going to try to find a solution that notifies me on a hardware event (plug-in or unplug). Failing that, I'll probably go your route. Thanks.

          1 Reply Last reply
          2
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            I tried using libusb...fails a test and returns this message:

            Hotplug capabilites are not supported on this platform

            I could build my own copy so I could step through the debugger, but I think I'll just punt and go with Joel's idea, unless anyone has another suggestions.

            mrjjM 1 Reply Last reply
            0
            • mzimmersM mzimmers

              I tried using libusb...fails a test and returns this message:

              Hotplug capabilites are not supported on this platform

              I could build my own copy so I could step through the debugger, but I think I'll just punt and go with Joel's idea, unless anyone has another suggestions.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @mzimmers

              Hi does the hotplug usb-serials show up in
              http://doc.qt.io/qt-5/qtserialport-enumerator-example.html

              1 Reply Last reply
              0
              • mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #7

                No, the ports displayed don't update while the program is running. I'm sure there's a hook somewhere in the bowels of .NET for this, but honestly, for this application, it's really not worth the trouble.

                mrjjM 1 Reply Last reply
                0
                • mzimmersM mzimmers

                  No, the ports displayed don't update while the program is running. I'm sure there's a hook somewhere in the bowels of .NET for this, but honestly, for this application, it's really not worth the trouble.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @mzimmers
                  Nope. But they are shown if you run it after?
                  There is no hotplug support as that is very system dependant.
                  But its easy to run rescan at a good time IF they are registered by the class.

                  mzimmersM 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @mzimmers
                    Nope. But they are shown if you run it after?
                    There is no hotplug support as that is very system dependant.
                    But its easy to run rescan at a good time IF they are registered by the class.

                    mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #9

                    @mrjj I'm not sure I understand your question. The output of the enumerator example doesn't change. Whatever it shows on startup is it.

                    mrjjM 1 Reply Last reply
                    0
                    • aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by aha_1980
                      #10

                      @mzimmers I have solved exactly this problem multiple times as @Joel-Bodenmann suggested. The only drawback I have found so far is when you unplug the currently selected device, as the UI does not reflect this. This could be solved by a QTimer polling the available devices every 5 seconds, though. (if the port is open while disconnecting, you should notice anyway)

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      1
                      • mzimmersM mzimmers

                        @mrjj I'm not sure I understand your question. The output of the enumerator example doesn't change. Whatever it shows on startup is it.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @mzimmers
                        There is no hotplug detection.
                        I was asking if the devices could be enumerated.
                        if yes, its easy to do as aha_1980 suggests.

                        1 Reply Last reply
                        0
                        • mzimmersM Offline
                          mzimmersM Offline
                          mzimmers
                          wrote on last edited by mzimmers
                          #12

                          I was able to get something of a dynamic list using this logic (CD_ComboBox is my custom class based on QComboBox):

                          void CD_ComboBox::findPorts()
                          {
                              QList<QSerialPortInfo> list = QSerialPortInfo::availablePorts();
                              QList<QSerialPortInfo>::iterator p;
                          
                              // clear the list first.
                              clear();
                          
                              // add the "title" to the combo box.
                              addItem("Select Port");
                          
                              for (p = list.begin(); p != list.end(); ++p)
                              {
                                  addItem(p->portName());
                              }
                          }
                          
                          1 Reply Last reply
                          1

                          • Login

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