QML 自定义属性

发布于 2024-10-01 12:40:30 字数 337 浏览 2 评论 0原文

我在 QML 项目中定义自定义属性时遇到问题:

Item {
    property MovieTileItem data
    Text {
        text: "Some text"
    }
}

MovieTitleItem 是在单独的 QML 文件中定义的项目:

import Qt 4.7

Item {
    property string title
    property string posterSource
}

我收到的错误是“无法将对象分配给属性”,指向属性声明。 有什么想法吗?

I'm having trouble defining a custom property in a QML item:

Item {
    property MovieTileItem data
    Text {
        text: "Some text"
    }
}

MovieTitleItem is an Item defined in a separate QML file :

import Qt 4.7

Item {
    property string title
    property string posterSource
}

The error I get is "Cannot assign object to property" pointing to the property declaration.
Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

虐人心 2024-10-08 12:40:30

“无法将对象分配给属性”,因为已经存在“数据”这样的属性(并且它是只读的):

http://qt-project.org/doc/qt-4.8/qml-item.html#data-prop

"Cannot assign object to property" because there is already such property as "data" (and it's read-only):

http://qt-project.org/doc/qt-4.8/qml-item.html#data-prop

素染倾城色 2024-10-08 12:40:30

我相信,如果自定义类型未使用 qmlRegisterType() 注册,则不能将其用作属性类型。以下可能会实现您正在寻找的东西

Item {
    data:Custom{}
    Text {
        text: "Some text"
    }
}

I believe, custom types can not be used as property types if they are not registered with qmlRegisterType(). Following may probably achieve what you are looking for

Item {
    data:Custom{}
    Text {
        text: "Some text"
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文