[PyQt] Problem with QDataStream and QString

Phil Thompson phil at riverbankcomputing.com
Mon Apr 14 16:41:33 BST 2008


On Friday 11 April 2008, İsmail Dönmez wrote:
> Hi again,
>
> Looks like I am back to QDataStream problems and here is the testcase :
> >>> from PyQt4.QtCore import *
> >>> a = QByteArray()
> >>> b = QDataStream(a, QIODevice.ReadWrite)
> >>> b << QString("123")
>
> <PyQt4.QtCore.QDataStream object at 0xa77e8e2c>
>
> >>> b.device().seek(0)
>
> True
>
> >>> b.readString()
>
> ''
>
> I was expecting the last output to be "123" instead of empty string.
> Any idea what I am doing wrong here?

Trying to read a string when you have written a QString. To read a QString...

s = QString()
b >> s

Phil



More information about the PyQt mailing list