Using context property in Javascript. How?
Unsolved
QML and Qt Quick
-
Hello all!
I got stacked in very simple issue. Totally forgotten how to call from JavaScript.
Here the example *.cppObjectType* oObject = new ObjectType(); oRootContext->setContextProperty("ObjectType",oObject);
in *.qml:
Component.onCompleted: { ObjectType.someMethod(); }
in *.js:
ObjectType.someMethod(); // this not working in JavaScript directly
What am I missing? How to make this method be working in JS directly?
-
@bogong Hi,
someMethod
must be a slot, or be annotated with Q_INVOKABLE macro. is it the case ?What do you mean by "this not working". Do you see any error ? Nothing happens?
edit: add codeclass ObjectType : public QObject { // Like this public slots: void someMethod(); // Or public: Q_INVOKABLE void someInvokableMethod(); }