...<other code>
MouseArea
{
anchors.fill: parent
onClicked:
{
console.log ("You clicked on tab!");
TabContainers.tabClicked (index);
}
}
...<other code>
This code in the file X.qml. Another file named TabContainers.qml contains a function named tabClicked.
I wish to call that function in file X.qml, so I tried:
TabContainers.tabClicked (index);
This gave me the error:
ReferenceError: TabContainers is not defined
How to call a function defined in a QML file in another QML file?
UPDATE:
This is what I tried:
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()
}
}
and the error I get is:
TestA.qml:15: TypeError: Object [object Object] has no method 'f'