use QAbstractListModel(c++) class in QML ComboBox



  • i tried these :

    ComboBox {
         width: parent.width * 0.9
         height: 40
         model: cplusplusModel.modelList
    }
    

    and i got:

    Unable to assign cplusplusModel to QString
    


  • What's the type of cplusplusModel.modelList ?
    Can you show the header ?



  • Not sure what is your model implementation.

    Here is the simple thing which works

    ComboBox {
        model: myModel
        textRole: "name"
    }
    
    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("myModel",&myModel);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    

    myModel is inherited from QAbstractListModel. name role is defined in the model.

    Can you share you model implementation ?



  • Thanks @dheerendra

    it worked!.
    i was omitting the textRole.

    My model type is :

    QList<QObject*>
    

Log in to reply
 

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