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?
Forum Updated to NodeBB v4.3 + New Features

Using context property in Javascript. How?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 171 Views 1 Watching
  • 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 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?

    Gojir4G 1 Reply Last reply
    0
    • B bogong

      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?

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on 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

      • Login

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