[PyQt] QList / SIP / Python weirdism...

Jamie Riotto jamie.riotto at gmail.com
Wed Dec 16 21:37:55 GMT 2009


Phil,
Ok, got it. All works as you proposed. I guess I'll hide the set/gets
behind properties on the python
side...

Thanks for the quick response!
Cheers - jamie


On Wed, Dec 16, 2009 at 12:53 PM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Wed, 16 Dec 2009 11:42:15 -0800, Jamie Riotto <jamie.riotto at gmail.com>
> wrote:
>> Ok, got my library working with QT classes (thanks Phil!), but I'm seeing
>> strange behavior with QList (I can set the list, but not append to
>> it). For example I have
>>
>> Object.h:
>>
>> Class Object() {
>> Public:
>>      Object();
>>      QString name;
>>      QList<int> testlist;
>> };
>>
>>
>> and Object.sip:
>>
>> %Import QtCore/QtCoremod.sip
>>
>> %Module ObjectLib 0
>>
>> class Object {
>> %TypeHeaderCode
>> #include "Object.h"
>> %End
>>
>> public:
>>      Object();
>>      QString name;
>>      QList<int> testlist;
>>
>> };
>>
>> Everything compiles / links ok (Windows, QT 4.5, SIP 4.6.1) but when I
>> run a Python shell I get:
>>
>> from ObjectLib import *
>>
>> foo = Object()
>> print foo.testlist
>>
>> foo.testlist.append(7)
>> print foo.testlist
>>
>> foo.testlist = [3,4,5]
>> print foo.testlist
>>
>> foo.testlist[0] = 9
>> print foo.testlist
>>
>> foo.testlist.pop(0)
>> print foo.testlist
>>
>> =========================================
>> Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
>> (Intel)] on win32
>> Type "copyright", "credits" or "license()" for more information.
>>>>>
>> [ ]
>> [ ]
>> [3, 4, 5]
>> [3, 4, 5]
>> [3, 4, 5]
>>>>>
>> ==============================================
>>
>>
>> I.e.the Append, the [ ] index operation and the Pop did not work. Am I
>> doing something wrong?
>
> You can only get and set the values, so...
>
> l = foo.testlist
> l.append(7)
> foo.testlist = l
>
> Phil
>



More information about the PyQt mailing list