QScriptEngine and QMetaObject
-
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,
QScriptEngine *engine)
{
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);
engine.globalObject().setProperty("QObject", metaObject);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?http://www.qtcentre.org/threads/59771-How-to-really-really-use-custom-QtScript-classes
Looking at the last post, he uses signals and slots:
@x.mySignal.connect(y.mySlot);@
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.
-
Hi,
No it's not, don't give a return value to a slot.
However, you can use Q_INVOKABLE for your purpose.