[Interest] QQmlPropertyList x QList in hybrid C++/QML APIs
Sandro Andrade
sandroandrade at kde.org
Mon Jun 17 19:44:45 CEST 2013
On Sun, Jun 16, 2013 at 6:27 AM, Stephen Kelly <stephen.kelly at kdab.com> wrote:
> On Friday, June 14, 2013 16:43:12 Sandro Andrade wrote:
>> Am I missing something ?
>
> The QML engine doesn't use the QVariant API for accessing things in a
> QVariant. So capabilities you have when using QVariant/Q_PROPERTY are not
> available in QML. This is probably fixable, but I'm not sure it's understood
> by the people who know QML well enough to fix it.
>
> QGuiApplication app(argc, argv);
>
> QList<QUmlObject*> l;
> QUmlObject *o1 = new QUmlObject;
> Q_SET_OBJECT_NAME(o1);
> l.push_back(o1);
> QUmlObject *o2 = new QUmlObject;
> Q_SET_OBJECT_NAME(o2);
> l.push_back(o2);
>
> QVariant v = QVariant::fromValue(l);
>
> if (v.canConvert<QVariantList>()) {
> QSequentialIterable seqIter = v.value<QSequentialIterable>();
> qDebug() << seqIter.size();
>
> foreach(const QVariant &item, seqIter) {
> qDebug() << item;
> }
> }
>
> QQmlEngine engine;
> engine.rootContext()->setContextProperty("_objList", v);
> QQmlComponent component(&engine);
> component.setData("import QtQuick 2.0\nItem { Component.onCompleted :
> console.log(_objList), _objList.length() }", QUrl());
> component.create();
>
>
> 2
> QVariant(QUmlObject*, QUmlObject(0xa05920, name = "o1") )
> QVariant(QUmlObject*, QUmlObject(0xa11190, name = "o2") )
> QVariant(QList<QUmlObject*>)
> <Unknown File>: TypeError: Object [object Object] has no method 'length'
>
>
Well, I'm directly registering all required data converted to
QVariantData by now.
I'll try to investigate further in the beginning of July.
Thanks Stephen and Allan,
>
>
> Thanks,
>
> --
> Stephen Kelly <stephen.kelly at kdab.com> | Software Engineer
> KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
> www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
> KDAB - Qt Experts - Platform-Independent Software Solutions
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
More information about the Interest
mailing list