Using QByteArray: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
===Introduction===
h3. Introduction


QByteArray is the Qt class to store a array of bytes. It is analogous to a char *. Unlike a QString, a QByteArray has no encoding information and makes no attempt to decode bytes into characters.
QByteArray is the Qt class to store a array of bytes. It is analogous to a char *. Unlike a QString, a QByteArray has no encoding information and makes no attempt to decode bytes into characters.


===Converting QByteArray to QString===
=== Converting QByteArray to QString ===


To convert a QByteArray to QString, one needs to specify the encoding. It is not possible to convert a QByteArray to QString without knowing the encoding. Once the encoding is known, one can use functions like QString::fromUtf8, QString::fromUcs4 or use QTextCodec::toUnicode().
To convert a QByteArray to QString, one needs to specify the encoding. It is not possible to convert a QByteArray to QString without knowing the encoding. Once the encoding is known, one can use functions like QString::fromUtf8, QString::fromUcs4 or use QTextCodec::toUnicode().


===QByteArray::fromRawData()===
=== QByteArray::fromRawData() ===


No copy. Copies point to raw data.
No copy. Copies point to raw data.


===QByteArray::constData===
=== QByteArray::constData ===
 
Prevent detach.

Revision as of 10:59, 24 February 2015

h3. Introduction

QByteArray is the Qt class to store a array of bytes. It is analogous to a char *. Unlike a QString, a QByteArray has no encoding information and makes no attempt to decode bytes into characters.

Converting QByteArray to QString

To convert a QByteArray to QString, one needs to specify the encoding. It is not possible to convert a QByteArray to QString without knowing the encoding. Once the encoding is known, one can use functions like QString::fromUtf8, QString::fromUcs4 or use QTextCodec::toUnicode().

QByteArray::fromRawData()

No copy. Copies point to raw data.

QByteArray::constData