【发布时间】:2014-01-28 18:47:20
【问题描述】:
我有一个 QML 类,其中有一个函数,其中一个 QStringList 作为参数。我能够从 QML 访问 C++ 模型中的其他项目就好了。
在我的 QML 中:
function recentFiles(recentFilesList)
{
//This writes "0" for some reason, although it should be "3"
console.log(recentFilesList.length)
//Causes error: "Unable to assign [undefined] to QString"
return recentFilesList[0]
}
...
Text {
text: recentFiles(rootObject.myModel.recentFiles)
}
在我的源文件中:
QStringList someModel::recentFiles() const
{
QStringList recentFiles;
recentFiles << "A" << "B" << "C";
return recentFiles;
}
在我的头文件中:
Q_INVOKABLE QStringList recentFiles() const;
最终,我试图让我的 QStringList 处理 QML ListView 对象,它会显示如下:
- 一个
- B
- C
【问题讨论】:
标签: javascript c++ qt qml