[Interest] C++/QML Sequence Type to JavaScript Array

Максим Бесчеревных bma at ro.ru
Thu Feb 18 11:32:12 CET 2016


In docs http://doc.qt.io/qt-5/qtqml-cppintegration-data.html mentioned:

"Certain C++ sequence types are supported transparently in QML as JavaScript Array types.
In particular, QML currently supports:
    QList<int>
    QList<qreal>
    QList<bool>
    QList<QString> and QStringList
    QList<QUrl>
Other sequence types are not supported transparently, and instead an instance of any other sequence type will be passed between QML and C++ as an opaque QVariantList."

Looks like that "opaque conversion" doesn't work:

    class MyData : public QObject {
        Q_OBJECT
        Q_PROPERTY(QList<QGeoCoordinate> path READ path WRITE setPath NOTIFY pathChanged)
    public:
        QList<QGeoCoordinate> path() {
                 return _path;
        }
    ...

MyData object filled with some data and exposed as context property to QML. At QML i imported QtPositioning, so QGeoCoordinate refers to coordinate QML basic type, but
    console.log(myData.path) prints QVariant(QList<QGeoCoordinate>)
    console.log(myData.path) prints undefined
- there is no sequence, no length.

Is it possible to expose QList<Type> sequence to QML, where Type known by meta object system and refers to QML basic type provided by an QtQuick module?
I know that i can expose C++ property of type QVariantList , but what is that opaque conversion mentioned in docs.

Maxim 


Максим Бесчеревных.


More information about the Interest mailing list