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. QTComboBox model returning fewer items that reported by rowCount(..)
QtWS25 Last Chance

QTComboBox model returning fewer items that reported by rowCount(..)

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.5k 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.
  • D Offline
    D Offline
    duckman
    wrote on last edited by
    #1

    using a model derived from QAbstractListModel and after expanding the list box once QComboBox requests fewer data items than what is returned by rowCount(...).

    A 1 Reply Last reply
    0
    • D duckman

      using a model derived from QAbstractListModel and after expanding the list box once QComboBox requests fewer data items than what is returned by rowCount(...).

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @duckman What do you mean by "expanding the list box once"? Also can we see the code for creating the model and qcombobox? Are you removing items from the model perchance?

      Definitely going to need to see some code to help with this. AFAIK there is no bug that mysteriously drops items from the model when shown. :)

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      1
      • D Offline
        D Offline
        duckman
        wrote on last edited by
        #3

        "expanding the list box once" means that once items have been added to the to the model, I click on the ComboBox to reveal the list box contents then hit escape to list the list box collapse. I then add a couple of items to the model then expand the list box again. the model returns the correct count but the ComboBox does not as for all of the model's list entries.

        Note that if I keep adding items to the model without expanding the list box and then expand the list box all of the items are visible but again after the list box expansion the model returns the correct count and the ComboBox only asks for a subset of the item.

        The model is derived from QAbstractListModel, the ComboBox is not editable and the only 2 functions the model implements are rowCount(...) and data(...)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi and welcome to devnet,

          Are you correctly implementing the notification part of your model modifications ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • D Offline
            D Offline
            duckman
            wrote on last edited by
            #5

            It is my understanding that whenever the model is modified it should emit a signal notifying the ui to update itself which causes rowCount(...) to be called followed by a data(...) call rowCount(...) number of times. Are there additional signals that should be emitted by my model or UI?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Take a look at the Model View Programming chapter of Qt's documentation, especially the Inserting and removing rows part.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • D Offline
                D Offline
                duckman
                wrote on last edited by
                #7

                Thanks for the tip, I was unaware that it was necessary to override insertRows(...) and removeRows(...).

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  It usually is when using custom types. Depending on your use case a QStringListModel might be enough for you.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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