访问不同 qml 文件中的项目 [英] access items in different qml files

查看:14
本文介绍了访问不同 qml 文件中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 qml 文件,每个文件都在我的应用程序中定义一个屏幕.有时,一个屏幕上的动作应该改变另一个屏幕上的项目.现在我通过设置来做到这一点属性Item buttonId 然后做

I have several qml files, each of them define a screen in my application. Sometimes, an action on one screen should change items on a different screen. Right now I do this through setting the property Item buttonId and then do

for (var i = 0; i < buttonId.parent.children.length; i++) {
   buttonId.parent.children[i].state="inactive"
}

是否可以直接访问不同文件中的项目/对象,例如通过他们的身份证?

Is it possible to access Items/Objects in different files directly, e.g. through their id?

推荐答案

除非您有该 qml 类型的实例或单例,否则您无法访问不同 qml 文件"中的对象.

You cannot access objects in "different qml files" unless you have an instance of that qml type or a singleton.

只有当试图访问它的对象是在它想通过 id 访问的对象的范围内创建时,才可能通过 id 访问.

Access through the id is only possibly if the object that tries to access it is created in the scope of the object it wants to access via the id.

您有多个屏幕,只需将它们公开为根 qml 对象的属性,然后由于动态范围,它们将可以从整个应用程序访问,除非它们被具有相同名称的不同属性遮蔽.

You you have several screens, simply expose them as properties of the root qml object, then they will be accessible from the entire application because of dynamic scoping, unless they are shadowed by a different property with the same name.

这篇关于访问不同 qml 文件中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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