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

Phil Thompson phil at riverbankcomputing.com
Wed Dec 16 20:53:54 GMT 2009


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