[Development] why is QJSEngine not modifying metaObject

Hausmann Simon Simon.Hausmann at theqtcompany.com
Wed Feb 11 08:11:26 CET 2015


Hi,

The short answer to your question is that the meta object system isn't really designed for this. In theory this could be implemented but it would come at a high cost for something that rarely happens. The qml engine supports this, but in qml this happens at type compilation time, not fully dynamic.


Simon

  Original Message
From: Rees, Kevron
Sent: Wednesday, February 11, 2015 00:52
To: development at qt-project.org
Subject: [Development] why is QJSEngine not modifying metaObject


test:

class Test : public QObject {
Q_OBJECT
public slots:
  QObject* createQObject() { return new QObject(); }
  void checkQObjectMetaObject(QObject* obj)
  {
    for(int i=0; i < object->metaObject()->methodCount(); i++)
    {
      qDebug() << "introspecting: " << object->metaObject()->method(i).name();
    }
  }
};

QJSEngine engine;
QJSValue value = engine.newQObject(new Test());
engine.globalObject().setProperty("test", value);

QString js = ""
"var coolObject = test.createQObject();" \
"coolObject.jsFunc = function() { return true; }"
"test.checkQObjectMetaObject(coolObject)";

engine.evaluate(js);

results:

jsFunc is not listed as a QMetaMethod.  Why?

-Kevron
_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development



More information about the Development mailing list