Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QJSEngine and C++ classes instanciated from JavaScript



  • Hello,

    with the old QtScript it was possible to define a JavaScript class which is based on a C++ class.

    The code for this purpose on C++ was
    @
    QScriptValue ctor = engine->newFunction(constructor);
    QScriptValue myScriptClass = engine->newQMetaObject(&QObject::staticMetaObject, ctor);
    engine.globalObject().setProperty("MyClass", myScriptClass);
    @

    Then it was possible to write in JavaScript
    @var x = new MyClass();@

    How can this be achieved with the new QJSEngine?

    Best regards,
    Nico


Log in to reply