Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Using context property in Javascript. How?

Using context property in Javascript. How?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 156 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bogong
    wrote on 18 Sept 2020, 13:32 last edited by
    #1

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

    ObjectType* 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?

    G 1 Reply Last reply 18 Sept 2020, 14:18
    0
    • B bogong
      18 Sept 2020, 13:32

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

      ObjectType* 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?

      G Offline
      G Offline
      Gojir4
      wrote on 18 Sept 2020, 14:18 last edited by Gojir4
      #2

      @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
      public:
          Q_INVOKABLE void someInvokableMethod();
      }
      
      1 Reply Last reply
      0

      1/2

      18 Sept 2020, 13:32

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved