Questions tagged [qbytearray]

A QByteArray is a class from the Qt toolkit which provides an array of bytes.

QByteArray is meant to replace char * arrays. It can hold both raw bytes, and 8-bit null-terminated strings. QByteArray is initialized as easy as this:

QByteArray myArray("Hello, world!");

It also makes sure that the string is always null-terminated.

QByteArray supports indexed and iterator-based access, as well as it has methods like append() or prepend(), replace(), and other of the kind.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

267 questions
8
votes
5 answers

QBitArray to QByteArray

When we create a text file with this text "ali ata bak", and we use this file as input for the program. The code is running normally. But when we enter "1111111111111111111111" this text in the textfile, Code isnt running expected. So What is the…
sivanzor
  • 95
  • 1
  • 9
8
votes
1 answer

QSerialPort readLine() extremely slow compared to readAll()

The data I'm reading from a serialport (in Qt, using QtSerialPort/QSerialPort) is separated by the newline '\n' and return '\r' characters, which is the way I intend to look at it for parsing. The line length may very, but it is very easy to extract…
Rachael
  • 1,965
  • 4
  • 29
  • 55
6
votes
1 answer

Convert QString into QByteArray with either UTF-8 or Latin1 encoding

I would like to covert a QString into either a utf8 or a latin1 QByteArray, but today I get everything as utf8. And I am testing this with some char in the higher segment of latin1 higher than 0x7f, where the german ü is a good example. If I do…
Johan
  • 20,067
  • 28
  • 92
  • 110
6
votes
2 answers

Qt QString to QByteArray and back

I have a problem with tranformation from QString to QByteArray and then back to QString: int main() { QString s; for(int i = 0; i < 65536; i++) { s.append(QChar(i)); } QByteArray ba = s.toUtf8(); QString s1 =…
JanSLO
  • 388
  • 2
  • 9
6
votes
3 answers

Internal reallocation behaviour of QByteArray vs reserve()

I just tried to optimize some communication stack. I am using Qt 5.3.2 / VS2013. The stack uses a QByteArray as a data buffer. I intended to use the capacity() and reserve() methods to reduce unnecessary internal buffer reallocations while the data…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
6
votes
3 answers

QbyteArray data copy

I have two QByteArray, sData and dData. I want to copy n bytes from location x in dData i.e. &dData[x] to location y of sData i.e. &sData[y]. In C, array copy is done by memcpy(&dData[x], &sData[y], n); How could copying above data of QByteArray be…
beparas
  • 1,927
  • 7
  • 24
  • 30
5
votes
3 answers

C++, Qt - splitting a QByteArray as fast as possible

I'm trying to split a massive QByteArray which contains UTF-8 encoded plain text(using whitespace as delimiter) with the best performance possible. I found that I can achieve much better results if I convert the array to QString first. I tried using…
user129186
  • 1,156
  • 2
  • 14
  • 30
5
votes
2 answers

How do I see the contents of Qt objects QByteArray during debugging?

My program use some variables of type QByteArray to contain data (bytes). That bytes maybe are special characters like '\0', 1, ... So I cannot see all elements after special character when debugging. If I use std::vector, I can see all elements. I…
aviit
  • 1,957
  • 1
  • 27
  • 50
4
votes
2 answers

How can I partition a QByteArray efficiently?

I want to partition a QByteArray message efficiently, so this function I implemented take the Bytes, the part I want to extract, and toEnd flag which tells if I want to extract part1 till the end of the array. my dilimeter is spcae ' ' example if I…
gehad
  • 1,205
  • 3
  • 12
  • 17
4
votes
4 answers

Why size of QByteArray is `int` rather than `unsigned int`

I have such expressions in my code: QByteArray idx0 = ... unsigned short ushortIdx0; if ( idx0.size() >= sizeof(ushortIdx0) ) { // Do something } But I'm getting the warning: warning: comparison between signed and unsigned integer…
Megidd
  • 7,089
  • 6
  • 65
  • 142
4
votes
1 answer

Convert QByteArray from big endian to little endian

I think I’m a kind of at a loss here. I trying such a simple thing, I can’t believe that there is nothing build-in Qt (using Qt 5.6.2). I try to convert the data inside a QByteArray from big endian to little endian. Always starts with the same test…
sandkasten
  • 603
  • 1
  • 8
  • 21
4
votes
3 answers

Standard replacement for QByteArray

I want to port a Qt C++11 function to standard C++11. The function has a QByteArray parameter that accepts any kind of data (text, binary data, etc.) and calculates a hash from the data. QByteArray seems well suited because it can carry any kind of…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
4
votes
2 answers

Ensure a QByteArray owns its memory (QByteArray::fromRawData)

Say we have a function store void store(const QByteArray& data); This function's job is to take data and store it away. Unfortunately, it is not safe to do that if the argument was created with QByteArray::fromRawData(ptr, size), because it and all…
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
4
votes
1 answer

Append quint16/unsigned short to QByteArray quickly

In my project I'm working with QByteArrays appending data to them as the program goes. Most of the time, a simple quint8 gets appended just fine using QByteArray::append(). But when a quint16 gets appended, only 1 byte gets appended instead of…
mrg95
  • 2,371
  • 11
  • 46
  • 89
4
votes
1 answer

Replace method changes size of QByteArray

I want to manipulate a 32 bit write command which I have stored in a QByteArray. But the thing that confuses me is that my QByteArray changes size and I cannot figure out why that happens. My code: const char CMREFCTL[] =…
Mindstormer
  • 73
  • 2
  • 6
1
2
3
17 18