Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QScriptEngine and QMetaObject
kovand11 last edited by
I am working based on the documentation of QScriptEngine with QMetaObject.
I made my own class, inherited from QObject. It seems to work, but I have some problems.
@ QScriptValue mySpecialQObjectConstructor(QScriptContext *context,
QObject *parent = context->argument(0).toQObject();
QObject *object = new QObject(parent);
return engine->newQObject(object, QScriptEngine::ScriptOwnership);
QScriptValue ctor = engine.newFunction(mySpecialQObjectConstructor);
QScriptValue metaObject = engine.newQMetaObject(&QObject::staticMetaObject, ctor);
QScriptValue result = engine.evaluate("new QObject()");@
Firstly, I can call the slots, but not the normal functions, from the script side. Why is that?
If I give return value to my slots it seems to work, Is it a good practice?
Looking at the last post, he uses signals and slots:
What can be at the place of y.mySlot? Surely I can use an another registered QMetaObject. But can I use registered standalone functions? Or script side functions?
Thanks in advance.
No it's not, don't give a return value to a slot.
However, you can use Q_INVOKABLE for your purpose.