Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make a JS property assigned a function?
QtWS25 Last Chance

How to make a JS property assigned a function?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.1k 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.
  • Y Offline
    Y Offline
    yl28365
    wrote on last edited by
    #1

    Hi ,

    I recently meet a problem, which is how define a property in C++ file and in js file it could be assigned to a function.
    

    mainview.h
    @
    #define XXX QScriptValue
    class MyView : public QObject{
    Q_OBJECT
    Q_PROPERTY(QScriptValue value READ getValue WRITE setValue SCRIPTABLE true);

    public slots:
    XXX  getValue() const;
    void setValue(const XXX &a);
    
    };
    

    @
    js file:
    @
    var app1 = document.getElementById("app1");
    app1.value= funcTest;

    function   funcTest(abc) {
    

    var j = 12345;
    alert(abc);
    }
    @
    Now I found that, if I use "QString" in Q_PROPERTY(QString value READ getValue WRITE setValue SCRIPTABLE true), the function funcTest could be assinged, but how could this function funcTest be called?
    And in
    @
    void setValue(const XXX &a);

    };
    

    @
    "a" could be recognized as a function.

    Could anyone could help me with this problem?
    Thank you!

    Edit: please use @ tags around code sections; Andre

    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