我是QT QML的新手。我在c++文件(audioinput.cpp(中有一个字符串列表,在QML文件(voiceCall.QML(中有个组合框。我需要用这个列表的字符串填充这个组合框的项目。
我的列表定义是->
List<Qstring> lst .
我的组合框定义是:
ComboBox {
id: comboBox
x: 200
y: 95
objectName: "speakers"
width: 244
height: 32
model: []
}
C++:
QQuickView view;
QStringList comboBoxModel = { "one", "two", "three" };
view.rootContext()->setContextProperty("comboBoxModel", &comboBoxModel);
view.setSource("main.qml");
view.show();
QML:
Combobox {
model: comboBoxModel
}
QStringList继承自QList<Q字符串>。