Conversion between qbytearray and Python bytes

Source: Internet
Author: User

Pyside or pyqt does not have the qstring type in pythonv3, and is replaced by the STR type in Python. However, qbytearray exists. During pyside usage, conversion between qbytearray and Python bytes may be used. Google generally means that no conversion is required between qbytearray and bytes. In fact, eoferro is generated when qdatastream> bytes () is used. The following code:

Before Modification
  • Output first

Qdatasteam out (file)

Out <OBJ # obj is a python bytes object.

  • Then read

Qdatastring in (file)

OBJ = bytes ()

In> OBJ # generate eoferro

After modification

The Code is as follows:

  • Output first

Qdatasteam out (file)

Out <qbytearray (OBJ) # obj is a python bytes object.

# Because c ++ has implicit conversion, it can also be used as follows:

Out <OBJ

  • Then read:

Qdatastring in (file)

TMP = qbytearray ()

In> TMP

OBJ = bytes (TMP. Data () # The read obj is the binary object to be saved.

To sum up:

C ++ implicitly converts the output stream. c ++ does not implicitly convert the input stream. In any case, manual conversion is the most secure.

  • Bytes ---> qbytearray is:

OBJ = bytes ()

Qbyte = qbytearray (OBJ)

  • Qbytesarray ----> bytes is:

Qbyte = qbytearray ()

OBJ = qbyte. Data () or OBJ = bytes (qbyte. Data ())

This problem occurs when I use pickle and QT in serialization.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.