[Interest] QML objects and QMetaMethod

Jean-Michaël Celerier jeanmichael.celerier at gmail.com
Sun Oct 7 12:34:29 CEST 2018


Hello,
I have the following code :

Foo.qml :

    MyLib.MyObject {
      function createTree() { /* stuff */ }
      property string host: "ws://whatever.com"
    }

cpp :

    namespace lib {
      class MyObject : public QObject { Q_OBJECT };
    }
    ...
    QQmlComponent c(engine);
    c.setData("content of Foo.qml", QUrl());

    auto obj = c.createObject();
    QString host = QQmlProperty(obj, "host").read();
    QMetaMethod::invokeMethod("createTree");

Reading the "host" property works fine so the QML object is correctly
instantiated. But the invokeMethod call gives me a warning :

    QMetaObject::invokeMethod: No such method 'lib::MyObject::createTree()'

The weird thing being: it works fine if I replace MyLib.MyObject with
QtObject on the QML side.
Of course I want to use some additional methods present in MyObject so this
is not a solution.

Anyone knows what is going on here ?

Thanks,
Jean-Michaël Celerier





-------
Jean-Michaël Celerier
http://www.jcelerier.name
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181007/a7f17823/attachment.html>


More information about the Interest mailing list