ListElement 字段作为属性? [英] ListElement fields as properties?

查看:8
本文介绍了ListElement 字段作为属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

import QtQuick 1.0

ListModel {
    property real firstValue: 2
    property real secondValue: 3
    property real thirdValue: 1
    id: leftGrid
    ListElement {
        icon: "Images/1.png"
        value: leftGrid.firstValue
    }
    ListElement {
        icon: "2.png"
        value: -1
    }
    ListElement {
        icon: "3.png"
        value: leftGrid.secondValue
    }
    ListElement {
        icon: "4.png"
        value: leftGrid.thirdValue
    }
}

这给了我错误:

ListElement: cannot use script for property value

我该怎么办?

推荐答案

我也遇到了这个问题.考虑采用此处报告的解决方案之一:https://bugreports.qt.io/browse/QTBUG-16289 根据您的 Qt 版本解释.

I had this problem as well. Consider adopting one of the solutions reported in here: https://bugreports.qt.io/browse/QTBUG-16289 according to your version of Qt as explained.

我个人更喜欢用 C++ 实现模型.阅读:http:///cdumez.blogspot.com/2010/11/how-to-use-c-list-model-in-qml.html.

I personally prefer to implement the model in C++. Read this: http://cdumez.blogspot.com/2010/11/how-to-use-c-list-model-in-qml.html.

这篇关于ListElement 字段作为属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆