QML基本问题 求指导

tt2com 2012-07-04 11:00:26
A.qml中一个function fuc()
我将A放入B.qml中


Item{
id: b
width:100
heigt: 100
A{
id: a1
???? //我想在此处调用fuc() 该如何实现?
}
}

...全文
83 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tt2com 2012-07-04
  • 打赏
  • 举报
回复
非常感谢
tt2com 2012-07-04
  • 打赏
  • 举报
回复
Running JavaScript at StartupIt is occasionally necessary to run some imperative code at application (or component instance) startup. While it is tempting to just include the startup script as global code in an external script file, this can have severe limitations as the QML environment may not have been fully established. For example, some objects might not have been created or some Property Bindings may not have been run. QML JavaScript Restrictions covers the exact limitations of global script code.

The QML Component element provides an attached onCompleted property that can be used to trigger the execution of script code at startup after the QML environment has been completely established. For example:

Rectangle {
function startupFunction() {
// ... startup code
}

Component.onCompleted: startupFunction();
}Any element in a QML file - including nested elements and nested QML component instances - can use this attached property. If there is more than one onCompleted() handler to execute at startup, they are run sequentially in an undefined order.

Likewise, the Component::onDestruction attached property is triggered on component destruction.
Vegata 2012-07-04
  • 打赏
  • 举报
回复
可以这样调用

Item{
id: b
width:100
heigt: 100
A{
id: a1
Component.onCompleted: func()
}
}
Vegata 2012-07-04
  • 打赏
  • 举报
回复
Item{
id: b
width:100
heigt: 100
A{
id: a1
Component.onCompleted: fuc()
}
}
你说的那个位置这能这样了
tt2com 2012-07-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

你指的调用,是象constructor一样的调用?还是被某个事件触发后调用?
文档这里有:http://qt-project.org/doc/qt-4.8/qdeclarativejavascript.html
[/Quote]
类似constructor一样调用。
zhu_xz 2012-07-04
  • 打赏
  • 举报
回复
你指的调用,是象constructor一样的调用?还是被某个事件触发后调用?
文档这里有:http://qt-project.org/doc/qt-4.8/qdeclarativejavascript.html

16,228

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧