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. problem to display a QStringList in a model in a ComboBox
Forum Updated to NodeBB v4.3 + New Features

problem to display a QStringList in a model in a ComboBox

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 1.1k 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.
  • C Offline
    C Offline
    cosmoff
    wrote on last edited by
    #1

    Hello everybody

    first of all, my comboBox works because when I run my app, I see my QStringList in my ComboBox. I precise that my QStringList is filled thanks to a server which send the paramaters for the QStringList.
    The problem appears when I switch off and switch on the server. When I switch off the server, I empty my QStringList with a clear(). And When I switch on my server, I retrieve
    correctly my data (QStringList is well filled) but The probleme come from the QML. the Qml do not run the methode "selectedTechno"
    which allow to retrieve a pointer. When I run the app, Qml calls this methode but never when I restart my server. Is it normal ?

    this is my combobox :

    ComboBox{
                        model:  model.selectedTechno ? model.selectedTechno.qstringList : null
    
    
                        anchors {
                            left: parent.left
                        }
    
                        width: 0.5 * parent.width
                    }
    
                thanks for your help.
    
    1 Reply Last reply
    0
    • IntruderExcluderI Offline
      IntruderExcluderI Offline
      IntruderExcluder
      wrote on last edited by IntruderExcluder
      #2

      This is because nothing changed for QML. Your string list is the same object before and after refilling. There is two ways to do what you want:

      1. Use QStringListModel istead of QStringList;
      2. Define your string list as QObject property via Q_PROPERTY with proper notification about changes.
      1 Reply Last reply
      0
      • C Offline
        C Offline
        cosmoff
        wrote on last edited by cosmoff
        #3

        I already done
        Q_PROPERTY ( QStringList qstringList READ qstringList NOTIFY qstringListChanged ) and it does not work. I think
        the problem come from the fonction selectedTechno() because it is never called

        1 Reply Last reply
        0
        • IntruderExcluderI Offline
          IntruderExcluderI Offline
          IntruderExcluder
          wrote on last edited by IntruderExcluder
          #4

          If selectedTechno is QObject pointer exposed to QML you can try this:

          ...
          ComboBox {
              id: cbox
              ...
          }
          
          Connections {
              target: model.selectedTechno
              onQstringListChanged: {
                  cbox.model = model.selectedTechno.qstringList;
              }
          }
          

          Hope this helps, but more info required.

          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