[Interest] QQmlPropertyList x QList in hybrid C++/QML APIs
Stephen Kelly
stephen.kelly at kdab.com
Sun Jun 16 11:27:06 CEST 2013
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'
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130616/340ad5c1/attachment.sig>
More information about the Interest
mailing list