...<other code>
MouseArea
{
anchors.fill: parent
onClicked:
{
console.log ("You clicked on tab!");
TabContainers.tabClicked (index);
}
}
...<other code>
此代码在文件中X.qml
。名为的另一个文件TabContainers.qml
包含名为的函数tabClicked
。
我想在file中调用该函数X.qml
,所以我尝试了:
TabContainers.tabClicked (index);
这给了我错误:
ReferenceError: TabContainers is not defined
如何在另一个QML文件中的QML文件中调用定义的函数?
更新:
这是我尝试的:
TestB.qml
import QtQuick 2.0
Rectangle
{
id: myItem
width: 100; height: 100
function f ()
{
console.log ("sadsad");
}
}
TestA.qml
import QtQuick 2.0
Item
{
width: 100; height: 100
Loader
{
id: myLoader
source: "TestB.qml"
}
Connections
{
target: myLoader.f()
}
}
我得到的错误是:
TestA.qml:15: TypeError: Object [object Object] has no method 'f'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句