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. >From the C++ code in sipqtQImage.cpp, here's some of the actual code your Python constructor call will execute: uchar *a0; int a1; int a2; int a3; PyObject *a4; int a5; int a6; if (sipParseArgs (&sipArgsParsed, sipArgs, "siiiNie", &a0,&a1,&a2,&a3,&PyList_Type,&a4,&a5,&a6)) >From the type for a0 (and the "s" in the format string - the complete format string is "siiiNie"), "yourdata" is simply a Python string. a4 is the Python list of QRgb instances. The reason you're getting the error message about "too many arguments" is that there is a constructor that takes a list of strings as its only argument, and the code thinks you're calling that constructor.. You want 'buffer' to be a Python string, not a list to call the constructor you're calling. I haven't needed to figure out how to put 8 bit chars into a string efficiently, but you can do things like: buffer = "a" + chr (255) or buffer = "a\xff" I think Detlev draws some icons in some of the eric Python code - I'm not sure if they're QImages, but the method should be similar. If you have eric, you can take a look at that. Jim _______________________________________________ PyKDE mailing list [EMAIL PROTECTED] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde