c++ - 从 Qt 中的 c++ 文件快速填充组合框项目
问题描述
我是 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<QString>。
推荐阅读
- reactjs - 如何将带有所有组件的 React js Web 应用程序部署到 Amazon Web Services 放大?
- ruby-on-rails - 您如何更改活动管理员搜索记录的方式
- python - 使用 SparseVector PySpark 创建数据框
- java - LifecycleRegistry 在 MVP 架构的 BaseActivity 中未初始化
- vue.js - 路由查询导致“找不到此页面” - Nuxt JS
- postgresql - 无法使用 kotlin 和 spring 数据持久化数据
- angular - 从 Dexie 集合中读取第一条记录,包括 ID
- python - 遍历列表列表并划分列表值
- python - 我们如何使用 python 在活动屏幕上绘图
- java - 我无法停止音乐