Hi All,
Im probably being really dumb and staring right at the issue but can't see the solution.. I've written an import library that we use for various Qt 4.8 QML applications. I have various objects that i can instantiate inside QML without any problem e.g.
Logger {
id: write;
name: "Main.qml";
Component.onCompleted: {
log("log started");
}
}
Logger {
id: write;
name: "Main.qml";
Component.onCompleted: {
log("log started");
}
}
To copy to clipboard, switch view to plain text mode
and as expected, have access to this "Logger" components "log" method e.g.
MouseArea {
anchors.fill: parent;
onClicked: {
write.log("Mouse area clicked)
console.log(convert.time_ms_to_sec(-1));
console.log(convert.time_ms_to_sec(15000));
}
}
MouseArea {
anchors.fill: parent;
onClicked: {
write.log("Mouse area clicked)
console.log(convert.time_ms_to_sec(-1));
console.log(convert.time_ms_to_sec(15000));
}
}
To copy to clipboard, switch view to plain text mode
This all works fine. My problem is that i now want to create some global functions inside my import library that can be called from anywhere without having to instantiate an object in every QML file. For example, i made a test function that converts milliseconds to seconds, but in order to use it i have to declare my "Conversion" object in each QML file, like..
Conversion {
id: convert;
}
MouseArea {
anchors.fill: parent;
onClicked: {
console.log(convert.time_ms_to_sec(15000));
}
}
Conversion {
id: convert;
}
MouseArea {
anchors.fill: parent;
onClicked: {
console.log(convert.time_ms_to_sec(15000));
}
}
To copy to clipboard, switch view to plain text mode
Is there a way of doing this without having to declare the "Conversion {}"?!? I want to be able to simply call convert.time_ms_to_sec(<val>) in any script that has my import.
Thanks in advanced,
Raab.
Bookmarks