当我的委托组件在console.log()函数中使用时,它的索引属性无法识别:
onClicked: {
identities.qml_del_account(index);
console.log(index);
}
/*Application output:*/
qrc:/Accounts2.qml:74: ReferenceError: index is not defined
第74行是:
console.log(index);
为什么它对第一行有效,但在第二行失败呢?这两行位于相同的javascript函数中。
完整的QML代码是:
Identities {
我有一个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"
在c++中定义了一个简单的c++,通过自定义Delegate和DelegateModel在QML ListView中显示。ListView可以通过拖放重新排序:
// The DropArea is part of the delegate `comp_container`
DropArea{
anchors{fill: parent}
keys: ["pageitem"]
onEntered: {
let from = drag.source.DelegateModel.itemsIndex
let to = dragA
在Listview中,我使用“委托”弹出了100项,假设listview已经显示了填充的值。现在我想从C++提取QML列表视图中已经显示的值。如何做到这一点?注意:我不能直接访问数据模型,,因为我使用隐藏变量在委托中进行过滤。
/*This is not working code, Please note,
delegate will not display all model data.*/
ListView
{
id:"listview"
model:datamodel