can a QComboBox notify when clicked?

  • 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...

  • @mzimmers

    You know, there is a list of signals you can use in QComboBox:

    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.

  • 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.

  • @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.

  • 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.

  • Qt Champions 2016


    Hi does the hotplug usb-serials show up in

  • 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.

  • Qt Champions 2016

    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.

  • @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.

  • @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 Champions 2016

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

  • 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.
        // add the "title" to the combo box.
        addItem("Select Port");
        for (p = list.begin(); p != list.end(); ++p)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.