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. Pass Java Script function to C++ method
Forum Update on Monday, May 27th 2025

Pass Java Script function to C++ method

Scheduled Pinned Locked Moved QML and Qt Quick
qml
2 Posts 1 Posters 787 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.
  • R Offline
    R Offline
    Rem-Kolomna
    wrote on last edited by
    #1

    I declare my object in C++

    class Action : public QObject
    {
      Q_OBJECT
      Q_PROPERTY(QString name READ name)
    public:
      Action(): QObject(0) {}
      QString name() const { return "rem"; }
      Q_INVOKABLE void getData() {};
    }
    

    and make it available to qml:

    engine()->rootContext()->setContextProperty("action", new Action());

    How to pass to getData() method javascript function as parameter and call this function on C++ side?

    So from QML point of view it should looks like:

    action.getData(function(data) { alert(data); });

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rem-Kolomna
      wrote on last edited by
      #2

      I found solution!

      Q_INVOKABLE void getCount(QJSValue function)
      {
        function.call(QJSValueList() << "qqww");
      }
      
      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