[PyKDE] C++ to Python Datatypes
Jim Bublitz
jbublitz at nwinternet.com
Mon Oct 13 07:36:01 BST 2003
On Sunday October 12 2003 17:41, Russell Valentine wrote:
> I'm having trouble sometimes figuring out what Python datatype
> goes with the C++ datatype.
>
> An example a 2x2 grayscale QImage:
>
> **C++ Define
>
> QImage ( uchar * yourdata, int w, int h, int depth, QRgb *
> colortable, int numColors, Endian bitOrder )
>
>
> How do you know what type to use for uchar *yourdata?
>
> **Python?
>
> grayColorMap = []
> for i in range(256):
> grayColorMap.append(QColor(i, i, i).rgb())
>
> buffer = []
> buffer.append(255) #white
> buffer.append(0) #black
> buffer.append(255) #white
> buffer.append(0) #black
>
> image = QImage(buffer, 2, 2, 8, grayColorMap, 256,
> QImage.IgnoreEndian)
>
>
> But I get:
>
> Traceback (most recent call last):
> File "./testQColor.py", line 22, 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: Too many arguments to QImage(), 1 at most expected
>
>
> I am confused. Thanks for any help!
Here is the method referenced from the PyQt docs:
"""
QImage(uchar *data, int w, int h, int depth, QRgb *colorTable,
int numColors, Endian bitOrder);
The colorTable parameter is a list of QRgb instances or None. (Qt
v2.1+)
"""
This probably won't clarify the uchar* parameter for you, but it
does indicate that the QRgb* parameter is a Python list of
QRgb instances or None.
More information about the PyQt
mailing list