Hello, You would need to use QDeclarativeListProperty aka "list properties". We have several documents on this already: 1)http://doc.qt.nokia.com/4.7-snapshot/gettingstartedqml.html#creating-qml-properties-in-a-c-class 2)http://doc.qt.nokia.com/4.7-snapshot/declarative-tutorials-extending-chapter5-listproperties.html
To summarize: 1)Your list item must inherit from a QObject, so don't use QString. 2)You MUST create functions to append to your list. size(), at(), clear() functions aren't necessary. 3) Register the type into qml using qmlRegisterType() in C++. Cheers, Jerome P. ________________________________________ From: qt-qml-boun...@trolltech.com [qt-qml-boun...@trolltech.com] On Behalf Of ext Toni Leppänen [toni.leppa...@gmail.com] Sent: Thursday, September 30, 2010 12:01 PM To: qt-qml@trolltech.com Subject: [Qt-qml] Getting a list of strings from plugin I'm trying to return a list of strings from a plugin. I'm getting an error when trying to access the list: foo.qml:13: TypeError: Result of expression 'list' [undefined] is not an object. Can someone help me how to do this? Here's a simplified example what I've tried: foo.h ----- #include <QObject> #include <QString> #include <QDebug> class Foo : public QObject { Q_OBJECT public: Foo(QObject * parent = 0); ~Foo(); Q_INVOKABLE QList<QString> getList(); }; foo.cpp ------- #include "foo.h" Foo::Foo(QObject * parent) : QObject(parent) {} Foo::~Foo() {} QList<QString> Foo::getList() { QList<QString> list; list << "aa" << "bb"; return list; } foo.qml ------- import Foo 1.0 import Qt 4.7 Item { property variant list: [] Foo { id: plugin } Component.onCompleted: { list = plugin.getList(); console.debug(list[0]); console.debug(list[1]); } } Cheers, Toni _______________________________________________ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml _______________________________________________ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml