[Qt-qml] Getting a list of strings from plugin

Gregory Schlomoff gregory.schlomoff at gmail.com
Thu Sep 30 12:15:09 CEST 2010


you probably want to use QDeclarativeListProperty
cheers

greg

On Thu, Sep 30, 2010 at 5:01 PM, Toni Leppänen <toni.leppanen at gmail.com> wrote:
> 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 at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml
>




More information about the Qt-qml mailing list