PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 489 - PySide.QtGui.QImage with string buffer argument
: PySide.QtGui.QImage with string buffer argument
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: QtGui
: HEAD
: All All
: P2 normal
Assigned To: Marcelo Lira
:
:
:
  Show dependency treegraph
 
Reported: 2010-11-22 19:13 EET by david.trem
Modified: 2011-04-29 18:06 EEST (History)
12 users (show)

See Also:


Attachments
typesystem patch to fix this issue (2.94 KB, patch)
2010-11-25 09:55 EET, Pieter Palmers
Details

Note You need to log in before you can comment on or make changes to this bug.
Description david.trem 2010-11-22 19:13:18 EET
PySide.QtGui QImage does not have an equivalent to
PyQt4 QImage.__init__ (self, str, int, int, Format)
which take a string memory buffer as argument.
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qimage.html
Comment 1 Matti Airas 2010-11-23 04:39:16 EET
Prioritizing P3 - this bug will be fixed during the core dev team's next few
sprints.
Comment 2 Pieter Palmers 2010-11-25 09:55:06 EET
Created attachment 158 [details]
typesystem patch to fix this issue

This patch fixes this bug partially.

AFAICT it should completely fix it, but there is a problem in the generated
code: the QImageWrapper base class call uses "data_out" instead of "data"

i.o.w.,in the generated qimage_wrapper.cpp the following line:

QImageWrapper::QImageWrapper(const uchar * data, int width, int height,
QImage::Format format) : QImage(data_out, width, height, format) {

should be eiter:

QImageWrapper::QImageWrapper(const uchar * data, int width, int height,
QImage::Format format) : QImage(data, width, height, format) {

or:

QImageWrapper::QImageWrapper(const uchar * data_out, int width, int height,
QImage::Format format) : QImage(data_out, width, height, format) {

whichever fits the conventions best.

I was wondering whether I am missing something here or whether this is a bug in
the pyside toolchain. 

If I manually correct this in the generated source code, things compile fine
and the resulting PySide modules work as expected.

So the question is: can I use <modify-argument> + <conversion-rule> on an
argument of the class constructor? If so there might be a bug in the system. If
not, this patch won't help a lot.
Comment 3 Matti Airas 2010-11-25 10:00:52 EET
Now that there's (at least a partial) patch, I'll prioritize P2 - this will be
taken in the current sprint once any other feature items are dealt with.
Comment 4 Hugo Parente Lima 2010-11-25 10:47:47 EET
Pieter Palmers, it's a bug in PySide tool chain. A possibly workaround is to
use inject-code tag instead of conversion-rule.
Comment 5 Marcelo Lira 2010-12-06 17:59:33 EET
Fixed in commit PySide/0a5e353a.
Comment 6 Hugo Parente Lima 2010-12-20 11:26:08 EET
Closign bugs after release of 1.0.0 beta2.
Comment 7 Erwan M 2011-03-10 13:31:59 EET
Hi, I'm using the PySide release 1.0.0, but I still can't use the QImage
constructor properly... I'm having the following error:

TypeError: 'PySide.QtGui.QImage' called with wrong argument types:
  PySide.QtGui.QImage(str, int, int, PySide.QtGui.QImage.Format)
Supported signatures:
  PySide.QtGui.QImage()
  PySide.QtGui.QImage(PySide.QtGui.QImage)
  PySide.QtGui.QImage(PySide.QtCore.QSize, PySide.QtGui.QImage.Format)
  PySide.QtGui.QImage(QString, str = None)
  PySide.QtGui.QImage(int, int, PySide.QtGui.QImage.Format)
  PySide.QtGui.QImage(uchar, int, int, PySide.QtGui.QImage.Format)
  PySide.QtGui.QImage(uchar, int, int, int, PySide.QtGui.QImage.Format)

I thought the "uchar" argument was automatically converted from a Python
string, but it seems not to be the case. Do I have to cast it to something, or
anything else ?

Thanks !
Comment 8 Hugo Parente Lima 2011-03-10 19:58:07 EET
(In reply to comment #7)
> Hi, I'm using the PySide release 1.0.0, but I still can't use the QImage
> constructor properly... I'm having the following error:
> 
> TypeError: 'PySide.QtGui.QImage' called with wrong argument types:
>   PySide.QtGui.QImage(str, int, int, PySide.QtGui.QImage.Format)
> Supported signatures:
>   PySide.QtGui.QImage()
>   PySide.QtGui.QImage(PySide.QtGui.QImage)
>   PySide.QtGui.QImage(PySide.QtCore.QSize, PySide.QtGui.QImage.Format)
>   PySide.QtGui.QImage(QString, str = None)
>   PySide.QtGui.QImage(int, int, PySide.QtGui.QImage.Format)
>   PySide.QtGui.QImage(uchar, int, int, PySide.QtGui.QImage.Format)
>   PySide.QtGui.QImage(uchar, int, int, int, PySide.QtGui.QImage.Format)
> 
> I thought the "uchar" argument was automatically converted from a Python
> string, but it seems not to be the case. Do I have to cast it to something, or
> anything else ?

Try:

PySide.QtGui.QImage(buffer(YOUR_STR), int, int, PySide.QtGui.QImage.Format)

the uchar argument accepts Python buffer objects, str itself implements the
buffer protocol, do you have a small test case to attach? if so we can analyse
and re-open the bug if the test case is valid.

> Thanks !
Comment 9 Gerald 2011-03-16 11:27:43 EET
I've just been struggling with this for the last 4 hours and decided to give up
and post a bug, but it seems its already here.

For a simple test case, this will throw the exception Erwan M gets:
from PySide import QtGui
test = QtGui.QImage('aaaa',1,1,QtGui.QImage.Format_ARGB32)

While this works perfectly well:
from PySide import QtGui
test = QtGui.QImage(buffer('aaaa'),1,1,QtGui.QImage.Format_ARGB32) 

So the short of it seems to me that QImage.__init__ (self, str, int, int,
Format) as per the PyQt api is not implemented but a perfectly workable version
using Python buffers IS available.  This is fine except that the difference
isn't really documented anywhere that I could find.  I could see that 'uchar'
wasn't a Python string in the documentation but if it wasn't for Hugo's comment
I would probably have never figured out that a Python buffer would satisfy the
'uchar' type.

Gerald.
Comment 10 Hugo Parente Lima 2011-03-16 21:34:37 EET
(In reply to comment #9)
> I've just been struggling with this for the last 4 hours and decided to give up
> and post a bug, but it seems its already here.
> 
> For a simple test case, this will throw the exception Erwan M gets:
> from PySide import QtGui
> test = QtGui.QImage('aaaa',1,1,QtGui.QImage.Format_ARGB32)
> 
> While this works perfectly well:
> from PySide import QtGui
> test = QtGui.QImage(buffer('aaaa'),1,1,QtGui.QImage.Format_ARGB32) 
> 
> So the short of it seems to me that QImage.__init__ (self, str, int, int,
> Format) as per the PyQt api is not implemented but a perfectly workable version
> using Python buffers IS available.  This is fine except that the difference
> isn't really documented anywhere that I could find.  I could see that 'uchar'
> wasn't a Python string in the documentation but if it wasn't for Hugo's comment
> I would probably have never figured out that a Python buffer would satisfy the
> 'uchar' type.

You are right, this uchar shouldn't appear because it means nothing to Python,
I fixed this on my local working copy of pyside and I'm going to push it to
mainline soon.

Anyway I'll reopen the bug because str implements the buffer protocol, so the
call:

test = QtGui.QImage('aaaa',1,1,QtGui.QImage.Format_ARGB32)

*should* work and it isn't unless the first param be something different from
str and unicode but implementing the buffer protocol.

> Gerald.
Comment 11 Marcelo Lira 2011-04-01 23:57:50 EEST
Fixed in PySide/bbba1cc4.
Comment 12 renato filho 2011-04-29 18:06:12 EEST
PySide release 1.0.2