Important: Please read the Qt Code of Conduct -

problem to display a QStringList in a model in a ComboBox

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

                        model:  model.selectedTechno ? model.selectedTechno.qstringList : null
                        anchors {
                            left: parent.left
                        width: 0.5 * parent.width
                thanks for your help.

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

  • 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

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

Log in to reply