QML Combobox with QStringListModel
-
Hi all,
I have a QStringListModel which is configured using the setStringList method.
I'm trying to use this model in QML Combobox.
I can't find a way to do so.
Please suggest.
@Valerian
QStringListModel::setStringList()
is neither a slot nor declared invokable, thus you have no chance to call it from QML.
You would need to subclass QStringListModel class and add a callable method yourself. Don't forget to register this custom list model type. -
@Valerian
QStringListModel::setStringList()
is neither a slot nor declared invokable, thus you have no chance to call it from QML.
You would need to subclass QStringListModel class and add a callable method yourself. Don't forget to register this custom list model type.@raven-worx But QStringListModel inherits QAbstractItemModel.
And I have exposed this model to qml using setContextProperty but I can't find the role name to be used in QML
-
@raven-worx But QStringListModel inherits QAbstractItemModel.
And I have exposed this model to qml using setContextProperty but I can't find the role name to be used in QML
@Valerian
k, i thought you want to call the setStringList() method from within QML.
Try to register QStringListModel class - using qmlRegisterUncreatableType() is sufficient -
The missing piece is probably to specify "display" as a text role. Any
QAbstractItemModel
derivative model has a bunch of default roles.ComboBox
doesn't know which one to show:ComboBox { textRole: "display" // <== model: stringListModel anchors.centerIn: parent }
-
The missing piece is probably to specify "display" as a text role. Any
QAbstractItemModel
derivative model has a bunch of default roles.ComboBox
doesn't know which one to show:ComboBox { textRole: "display" // <== model: stringListModel anchors.centerIn: parent }