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 455 - QByteArray.data() cuts data to first '\x00' char
: QByteArray.data() cuts data to first '\x00' char
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: QtCore
: HEAD
: All All
: P3 normal
Assigned To: renato filho
:
:
:
  Show dependency treegraph
 
Reported: 2010-11-03 12:55 EET by Nikolay Saiko
Modified: 2010-11-25 17:48 EET (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikolay Saiko 2010-11-03 12:55:37 EET
QByteArray.data() returns python`s 'str' object.
But if there is zero byte in QByteArray.data(), all data will be cutted just
before this zero-byte.
For example:
    >>>b = QByteArray("Preved\x00Medved!")
    >>>b.data()  
    "Preved" # invalid!!!
    >>>[c for c in b] 
    ['P','r','e','v','e','d','','M','e','d','v','e','d','!'] # normal

Using s.data() will give us only "Preved".
This is correct for C language (I suppose the bug is in using 'strlen()' C
function), but incorrect for Python: 
    >>>s = 'Preved\x00Medved!'
    >>>s, s[6], ord(s[6])
    ("Preved\x00Medved!", '\x00', 0)

so the only way to get QByteArray`s data is following madness:
    >>>''.join([a if a!='' else '\x00' for a in b])
    "Preved\x00Medved!"
Comment 1 Hugo Parente Lima 2010-11-11 14:20:08 EET
Fixed in commit:

pyside/7013bd760e1ad46b31c019e0a11df504d6e2563e

Thanks for the bug report.
Comment 2 renato filho 2010-11-25 17:48:21 EET
released on 1.0.0~beta1