Quantcast
Viewing all articles
Browse latest Browse all 4972

Calling a funciton.

The “get_db()” function is a member function of the implicit type defined by your top QML file. To invoke it you need to resolve it on a reference of the instance. There are a few ways you can get access to a reference of the instance: either directly by id (if it’s in the same component scope), passing a reference to the object as a parameter of a function, storing a reference in a pragma library JavaScript resource, and so on. An example of the latter is included. eg: // shared.js .pragma library   var databaseObject = null function init(dbObj) {     databaseObject = dbObj; } // DatabaseAccess.qml import QtQuick 2.0 import QtQuick.LocalStorage 2.0 import "shared.js" as Shared Text {     id: root     ....     function get_db() {         ....     }       Component.onCompleted: Shared.init(root) } // OtherFile.qml import QtQuick 2.0 import "shared.js" as Shared Item {     Component.onCompleted: {         Shared.databaseObject.get_db(); // etc.     } } I’d suggest reading the documentation about attributes of objects (which includes properties, methods, the id, and so on) for more information about this stuff. Cheers, Chris.

Viewing all articles
Browse latest Browse all 4972

Trending Articles