[PyKDE] C++ to Python Datatypes

Jim Bublitz jbublitz at nwinternet.com
Tue Oct 14 08:21:01 BST 2003

On Monday October 13 2003 20:23, Russell Valentine wrote:
> On Sun, 12 Oct 2003 22:25:59 -0700

>  I notice this also in the documentation.
> """
> void rgb(int *r, int *g, int *b);
> This takes no parameters and returns the r, g and b values as
> a tuple. """

> So does this mean the

> QRgb QColor::rgb () const

> function is not implemented because void rgb(int *r, int *g,
> int *b) which takes no parameters takes over instead?

That appears to be the way PyQt 3.7 is coded. PyQt 3.8 reverses 
the order of the methods to this:

	QRgb rgb() const;  //[1]
	// Obsolete.
	void rgb(int *,int *,int *) const;  //[2]

In the C++ code generated,  the call matches the signature (or 
argument list) of [1] first, so [2] never gets executed (the 
opposite of 3.7). There's a new method "getRgb" that returns the 
tuple, but it's versioned for >= Qt3.2.0, and the old rgb() that 
returns a tuple isn't versioned out (but effectively is never 
called anymore).

> I try the following:
> grayColorMap = []
> for i in range(256):
>     grayColorMap.append(qRgb(i, i, i))

> grayColorMap = []
> for i in range(256):
>     grayColorMap.append(QColor(i, i, i).rgb())

> It likes the first one, but not the second one. It gives.

> Traceback (most recent call last):
>   File "./testQColor.py", line 21, in ?
>     image = QImage(buffer, 2, 2, 8, grayColorMap, 256,
> QImage.IgnoreEndian) File
> "/usr/lib/python2.2/site-packages/qt.py", line 439, in
> __init__ libqtc.sipCallCtor(123,self,args)
> TypeError: an integer is required

If you print grayColorMap, it's probably a list of tuples of 
ints, not a list of ints. 

> I must admit that qRgb(r,g,b) is better than making a
> QColor(r,g,b) and calling rgb() on it, so it isn't that big of
> a deal for me at the moment.

With PyQt- 3.8 I get:

>>> from qt import QColor
>>> QColor (0x0, 0x0, 0xff).rgb ()

so either of your versions should work with PyQt-3.8. 
Looks like the sip code changed. Are you running PyQt 3.7?


More information about the PyQt mailing list