Pass JavaScript function as parameter to C++ function

后端 未结 1 726
醉酒成梦
醉酒成梦 2021-02-08 13:40

I declare my object in C++

class Action : public QObject
{
  Q_OBJECT
  Q_PROPERTY(QString name READ name)
public:
  Action(): QObject(0) {}
  QString name() con         


        
1条回答
  •  太阳男子
    2021-02-08 14:00

    It is possible using QJSValue. For example:

    //C++
    Q_INVOKABLE void getData(QJSValue value) {
        if (value.isCallable()) {
            QJSValueList args;
            args << QJSValue("Hello, world!");
            value.call(args);
        }
    }
    
    //QML
    action.getData(function (data){console.log(data)});
    

    0 讨论(0)
提交回复
热议问题