Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ComboBox model change does not update graphical appearance every time

ComboBox model change does not update graphical appearance every time

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
linuxcombobox modelqmlqtquick
3 Posts 2 Posters 2.3k Views
  • 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.
  • P Offline
    P Offline
    Payeurp
    wrote on 22 Feb 2018, 21:48 last edited by
    #1

    Hello, I am quite new to Qt and Qt Quick and I am facing a problem with the update of an item when one of its properties changes.

    Basically I have a Combo Box which lists Bluetooth devices as they are discovered and lets the user select one of the devices listed for pairing. To populate the combo box item I use a ListModel to which I append the newly discovered Bluetooth devices. This is the slot which adds new items to the combo box (it is connected to a C++ signal):

    function slot_deviceDiscovered(deviceName){
        bluetoothPairing.comboInput.model.append({text: deviceName})
        if(bluetoothPairing.comboInput.currentIndex === -1)
        {
            bluetoothPairing.comboInput.currentIndex = 0
        }
    
        pairingButton.enable()
    }
    

    Now when a Bluetooth discovery process is triggered, the devices which are already paired are discovered right away and the signal is emitted really quickly (I find this to be a weird behavior but it's not the problem) which triggers the execution of the slot. However, these devices which are discovered almost instantly don't show up in the combo box although their info was correctly added to the model. Then, as more devices get eventually discovered, their info also get appended to the model. But for them, the combo box also updates itself properly and I can select them in the list.

    I'm having a hard time finding the reason why the combo box won't update for the initial devices but will for the subsequent ones.

    Any insight?

    R 1 Reply Last reply 23 Feb 2018, 07:58
    0
    • P Payeurp
      22 Feb 2018, 21:48

      Hello, I am quite new to Qt and Qt Quick and I am facing a problem with the update of an item when one of its properties changes.

      Basically I have a Combo Box which lists Bluetooth devices as they are discovered and lets the user select one of the devices listed for pairing. To populate the combo box item I use a ListModel to which I append the newly discovered Bluetooth devices. This is the slot which adds new items to the combo box (it is connected to a C++ signal):

      function slot_deviceDiscovered(deviceName){
          bluetoothPairing.comboInput.model.append({text: deviceName})
          if(bluetoothPairing.comboInput.currentIndex === -1)
          {
              bluetoothPairing.comboInput.currentIndex = 0
          }
      
          pairingButton.enable()
      }
      

      Now when a Bluetooth discovery process is triggered, the devices which are already paired are discovered right away and the signal is emitted really quickly (I find this to be a weird behavior but it's not the problem) which triggers the execution of the slot. However, these devices which are discovered almost instantly don't show up in the combo box although their info was correctly added to the model. Then, as more devices get eventually discovered, their info also get appended to the model. But for them, the combo box also updates itself properly and I can select them in the list.

      I'm having a hard time finding the reason why the combo box won't update for the initial devices but will for the subsequent ones.

      Any insight?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 23 Feb 2018, 07:58 last edited by
      #2

      @Payeurp
      i guess it's something that happens in the code you've not posted.
      Do you change/set the model in your code? It may be that the slot gets called before you replace the model?
      Or you do the connection of the slot too early?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Payeurp
        wrote on 23 Feb 2018, 15:01 last edited by
        #3

        @raven-worx Thanks for your answer. There is no other place in the code where I update/modify the model. Also the combo box is already created when the slot is connected and called, if this is what you meant. Initially I declare the combo box as such with an empty model:

        ComboBox {
            id: comboInput
            visible: false
            anchors.fill: parent
            model: ListModel {
                id: model
            }
        }
        

        And this is the connection in C++ (plus the code to get the settings view inside which the combo box exists):

        //Connect signals emitted and received by Settings Form
        m_pQmlRoot = qmlEngine.rootObjects()[0];
        item = qvariant_cast<QObject*>(m_pQmlRoot->property("settingsPage"));
        QObject::connect(bluetoothManager, SIGNAL(sig_DeviceDiscovered(QVariant)), item, SLOT(slot_deviceDiscovered(QVariant)));
        
        1 Reply Last reply
        0

        1/3

        22 Feb 2018, 21:48

        • Login

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