[Interest] QML QList<int> as modelData

Damian Ivanov damianatorrpm at gmail.com
Wed Jan 29 08:08:31 CET 2014


Hi Alan,

Appreciate your help. I found out that I can use a QStringList and
directly from qml use it as modelData lik
ListView{model:myStringList;delegate: Text {text:modelData}}, so I
converted Yesterday my QList<int> to a QStringList. But I really much
appreciate you answer, had no answers to my question for so long
here... I will when I'm finished with my program (open source) release
it and I hope it will give good examples for Qt/c++ beginners.

Thanks again.

2014/1/28 Alan Alpert <416365416c at gmail.com>:
> On Mon, Jan 27, 2014 at 1:21 AM, Damian Ivanov <damianatorrpm at gmail.com> wrote:
>> Hi,
>>
>> I have QML c++ plugin which I import inside the .qml files using
>> import MyPlugin 1.0
>> In the plugin I have a QList<int> which I want to expose to .qml for a
>> ListView(and other views) as the modelData. What is the right way to
>> do it?
>
> You can expose it as a context property,
> https://qt-project.org/doc/qt-5/qqmlcontext.html#setContextProperty-2
> , on the rootContext() of the QQmlEngine. Or you can make it a
> property on a singleton type:
> https://qt-project.org/doc/qt-5/qtqml-cppintegration-definetypes.html#registering-singleton-objects-with-a-singleton-type
> .
>
> --
> Alan Alpert



More information about the Interest mailing list