2

Since Qt 5.5 is actual, QtScript is deprecated. The replacement is Qt QML with QJSEngine. Now, I will rewrite my project to the new engine. I have some Classes like:

class Node : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QList<Node*> childs READ childs)

public:
    inline QList<Node*> childs() {
        return childsByID.values();
    }
    Q_INVOKABLE QList<Node*> someChilds(QString filter);
    Q_INVOKABLE Node* makeChild(/*some args*/); // returns maybe 0.

private:
    Node(Node* parent);

    QHash<QString, Node*> childsByID;
    QHash<QString, Node*> childsByXYZ;
};

Q_DECLARE_METATYPE(Node*)
Q_DECLARE_METATYPE(QList<Node*>)

and in QtScript registered this with:

qScriptRegisterMetaType(&engine, nodeToScriptValue, nodeFromScriptValue);
qScriptRegisterSequenceMetaType<QList<Node*>>(&engine);

In the new QJSEngine I register the Node with qmlRegisterUncreatableType. But, I don't find a way to register the QList.

Knows anybody the right way ?

p.i.g.
  • 2,815
  • 2
  • 24
  • 41
Rico
  • 33
  • 1
  • 1
  • 8
  • @hellofunk says "QList C++ sequence types are supported transparently in QML as JavaScript Array types" here: http://stackoverflow.com/questions/6438157/qml-how-to-read-a-qlist-from-c – Jay Jul 07 '15 at 19:13
  • No, only for QVariantList (QList) but I don't have a copy-constructor im my class witch is neeted to copy to QVariant. I don't like to copy all my QHash'es and other Vars. – Rico Jul 07 '15 at 19:30
  • I didn't think qobjects were copied because they're based on smart pointers. Sorry that did not work. – Jay Jul 07 '15 at 19:35

0 Answers0