Important: Please read the Qt Code of Conduct -

Using context property in Javascript. How?

  • Hello all!
    I got stacked in very simple issue. Totally forgotten how to call from JavaScript.
    Here the example *.cpp

    ObjectType* oObject = new ObjectType();

    in *.qml:

    Component.onCompleted: {

    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 code

    class ObjectType : public QObject {
    // Like this
    public slots:
        void someMethod();
    // Or
        Q_INVOKABLE void someInvokableMethod();

Log in to reply