2011/2/16 Luca Donaggio <dona...@gmail.com>:
> [...]
> From QML I can access all other "basic types" properties, but when I try to
> do anything with the python list, It doesn't work.
> Let's say my QObject is exposed as "myObj" to QML and "myList" is the
> property which holds the python list, neither looping through its elements:
>
> for (var i = 0;i<myObj.myList.length;i++) {}
>
> nor accessing a random element directly:
>
> Text {text: myObj.myList[1]}
>
> are working (the latter causing the error "Unable to assign [undefined] to
> QString text").
>
> How am I supposed to do this?
Which version of PySide are you using? Also, for me it works when
setting a Python list as context property directly; I haven't tried
with properties on QObjects, though.
Thomas
_______________________________________________
PySide mailing list
PyS...@lists.openbossa.org
http://lists.openbossa.org/listinfo/pyside
Hi Luca,
2011/2/16 Luca Donaggio <dona...@gmail.com>:
> [...]
> From QML I can access all other "basic types" properties, but when I try toWhich version of PySide are you using? Also, for me it works when
> do anything with the python list, It doesn't work.
> Let's say my QObject is exposed as "myObj" to QML and "myList" is the
> property which holds the python list, neither looping through its elements:
>
> for (var i = 0;i<myObj.myList.length;i++) {}
>
> nor accessing a random element directly:
>
> Text {text: myObj.myList[1]}
>
> are working (the latter causing the error "Unable to assign [undefined] to
> QString text").
>
> How am I supposed to do this?
setting a Python list as context property directly; I haven't tried
with properties on QObjects, though.
Thomas
2011/2/16 Luca Donaggio <dona...@gmail.com>:
> On Wed, Feb 16, 2011 at 4:43 PM, Thomas Perl <th....@gmail.com> wrote:
>> Which version of PySide are you using? Also, for me it works when
>> setting a Python list as context property directly; I haven't tried
>> with properties on QObjects, though.
>
> Sorry, I should have mentioned it in my first post!
> I'm using PySide 1.0.0~beta5 for Maemo.
> Unfortunately I can't set the list as a context property, as I need it from
> within a ListModel.
> Actually I'm setting it with something like this inside the QObject
> subclass:
>
> myList = Property(list, _myList, notify = changed)
>
> Maybe the "list" type is not the correct one?
I don't know about the internals, but I think "list" should be the
correct type. Not knowing what you want to do exactly with the list
and its items, maybe you could move the processing/iterating over the
list into Python land and just expose the result as a single value to
QML? Or if that doesn't work, another idea would be to subclass
QObject and give it slots that provide a list-like API (size(), get(),
...) - yep, that's ugly and might not be the fastest way of doing
things.
Apart from that, maybe opening a bug/feature request at
http://bugs.openbossa.org/ seems like a good idea (post the bug link
here after submitting), as this is something that developers would
expect to work, and if it can be supported from the technical point of
view (Shiboken?), it probably should be.
Thanks,
Maybe this would help:
http://lists.openbossa.org/pipermail/pyside/2010-December/001585.html
--
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia
That bug entry is a bit messy, but that's the bug its describing
(python list's cannot be used a QObject properties )
If you print out a list object, from QML, that has been set using
setContextProperty, you get something like this:
list is:[object Object],[object Object],[object Object]
However if you use that list object as a property on a QObject, and
print that out, you get:
thing.list is:QVariant(PySide::PyObjectWrapper)
Now I found this while trying to use QAbstractListModel as a property,
which suffers the same problem, however there is a workaround for
that, you simply specify the property as 'QObject' type and it all
works fine.
Aidan.
I just wrote you yesterday because I couldn't get PySide working from
the source package (which is needed to setup the mysql plugin manually)
on my Mac 10.6.6. I didn't get any answers, seems nobody has the same
problem or has a solution. I finally solved the problem and now
everything works great: MySql (incl. QMYSQL driver), qt and PySide. If
anybody has the same problem, let me know, I will send you the detailed
configure parameters.
Thanks anyway, have a nice evening!
Aaron
This is a bug guys, http://bugs.openbossa.org/show_bug.cgi?id=629
That bug entry is a bit messy, but that's the bug its describing
(python list's cannot be used a QObject properties )
If you print out a list object, from QML, that has been set using
setContextProperty, you get something like this:
list is:[object Object],[object Object],[object Object]
However if you use that list object as a property on a QObject, and
print that out, you get:
thing.list is:QVariant(PySide::PyObjectWrapper)
Now I found this while trying to use QAbstractListModel as a property,
which suffers the same problem, however there is a workaround for
that, you simply specify the property as 'QObject' type and it all
works fine.
Aidan.
That's some test code that should work.
Good news is also, you can return python lists as a 'role' from one of
your AbstractList, and it does work, you can also return another
AbstractList as a role and that works too. (there's an example of that
in the test code)
http://bugs.openbossa.org/show_bug.cgi?id=629
I've updated this with a much cleaner example of the bug. dict's are
affected too.