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 323 - Unable to write to QDataStream using the << operator
: Unable to write to QDataStream using the << operator
Status: CLOSED INVALID
Product: PySide
Classification: Unclassified
Component: PySide
: HEAD
: All All
: P3 normal
Assigned To: renato filho
:
:
:
  Show dependency treegraph
 
Reported: 2010-08-27 12:15 EEST by Matti Airas
Modified: 2011-01-21 16:05 EET (History)
8 users (show)

See Also:


Attachments
Sample code (268 bytes, text/x-python)
2010-08-27 12:15 EEST, Matti Airas
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matti Airas 2010-08-27 12:15:06 EEST
Created attachment 70 [details]
Sample code

In the attached example, writeString does something sensible, the << operator
doesn't.
Comment 1 Matti Airas 2010-08-27 12:18:35 EEST
Same issue applies to the >> operator as well.
Comment 2 Hugo Parente Lima 2010-08-27 13:49:49 EEST
operator>>(str) is impossible to implement because strings are immutable
objects in python, use readString instead.
Comment 3 Matti Airas 2010-08-27 16:04:55 EEST
Ah, so true! Just ran across those while fixing the examples and didn't think
too far.

In any case, both the << and >> operators in Python are so horribly ugly that
it's hard to think anyone could have implemented them in the first place...
Comment 4 Lauro Moura 2010-09-17 20:43:40 EEST
Just lifting up the ball: Why to removing them?
Comment 5 Lauro Moura 2010-09-17 20:43:56 EEST
I meant, why not removing them? :)
Comment 6 Matti Airas 2010-10-04 05:14:56 EEST
(In reply to comment #5)
> I meant, why not removing them? :)

I guess it's a bit late now, would break lots of existing functionality.
Perfect content for PySide 2, IMHO. :-)
Comment 7 Lauro Moura 2010-10-29 15:29:29 EEST
Current test covers <</>> usage with

QByteArray
QBitArray
QDate
QTime
QDateTime.

The current software uses writeInt, writeQString for them.
Comment 8 Matti Airas 2010-11-22 15:32:52 EET
The issue still exists and there might be software using the horrible << syntax
- bumping to P4.
Comment 9 Matti Airas 2010-11-22 15:33:05 EET
I mean, like this.
Comment 10 Matti Airas 2011-01-14 09:48:48 EET
I'm raising this to P3 - this could well be fixed before 1.0.
Comment 11 Hugo Parente Lima 2011-01-19 17:04:32 EET
Matti, there some problems in operator<< and operator>> for QDataStream:

operator>> is only possible for mutable objects, i.e. not integers or strings.

operator<<has the following problem:

As QDataStream is used to create a binary stream all those operator overloads
produces different behavious:

operator<<(unsigned int)
operator<<(unsigned short)
operator<<(int)
operator<<(short)
operator<<(long)
operator<<(unsigned long)

Python has just two kind of numbers, int and long, so when the Python user
writes:

s = QDataStream()
s << 2

We have no enough info to discover what version of operator<< should be called,
this is why we have the writeInt32, writeInt16, writeUInt16 like PyQt.

On the typesystem we only remove the operator<< and operator>> for number
types, so it still working for things like QDate, QTime etc as I checked:

In [19]: data = QByteArray()

In [20]: c
Out[20]: <PySide.QtGui.QColor(ARGB 1, 0, 0, 1)  at 0x1e82968>

In [21]: d
Out[21]: <PySide.QtGui.QColor(Invalid)  at 0x1e82148>

In [22]: s = QDataStream(data, QIODevice.WriteOnly)

In [23]: s << c
Out[23]: <PySide.QtCore.QDataStream object at 0x1e82a30>

In [24]: data.size()
Out[24]: 11

In [25]: del s

In [26]: data.size()
Out[26]: 11

In [27]: s = QDataStream(data, QIODevice.ReadOnly)

In [28]: d
Out[28]: <PySide.QtGui.QColor(Invalid)  at 0x1e82148>

In [29]: s >> d
Out[29]: <PySide.QtCore.QDataStream object at 0x1e82580>

In [30]: d
Out[30]: <PySide.QtGui.QColor(ARGB 1, 0, 0, 1)  at 0x1e82148>


So I need to know what operator<</operator>> overload is missing, despite of
the ones using numbers.
Comment 12 Matti Airas 2011-01-20 07:55:27 EET
(In reply to comment #11)

> operator>> is only possible for mutable objects, i.e. not integers or strings.

Yes, that's obvious. :-)


> Python has just two kind of numbers, int and long, so when the Python user
> writes:
> 
> s = QDataStream()
> s << 2
> 
> We have no enough info to discover what version of operator<< should be called,
> this is why we have the writeInt32, writeInt16, writeUInt16 like PyQt.

OK, I see the problem. So, maybe the best approach would be to treat the
operators deprecated?

However, I still think this is a valid bug: string serialization using the <<
operator should probably work. If you run the example and see the resulting
file, you'll see the issue. So, disregard the silly comment regarding the >>
operator, but try out the sample code. :-)
Comment 13 Hugo Parente Lima 2011-01-20 11:52:07 EET
(In reply to comment #12)
> OK, I see the problem. So, maybe the best approach would be to treat the
> operators deprecated?
> 
> However, I still think this is a valid bug: string serialization using the <<
> operator should probably work. If you run the example and see the resulting
> file, you'll see the issue. So, disregard the silly comment regarding the >>
> operator, but try out the sample code. :-)

I just tried with PySide from git HEAD
(c7b5d3ed9e9ca0c1c76b3e9b0830337c4b03c88e) and it works :-)
Comment 14 Hugo Parente Lima 2011-01-21 16:05:17 EET
Closed due to release of 1.0.0~beta4