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.

248 questions
49
votes
7 answers

QByteArray to QString

I'm having issues with QByteArray and QString. I'm reading a file and stores its information in a QByteArray. The file is in unicode, so it contains something like: t\0 e\0 s\0 t\0 \0 \0 I'm trying to compare this value to my specified value, but it…
Nika
  • 1,694
  • 3
  • 21
  • 40
31
votes
4 answers

Qt C++ QString to QByteArray Conversion

I have created an encrypt/decrypt program, when encrypting I store the encrypted QByteArray in a text file. When trying to decrypt I retrieved it and then put it into the decryption method, the problem is that I need a way to convert it to…
James
  • 658
  • 1
  • 6
  • 13
12
votes
1 answer

QByteArray seen as a String in Javascript via QWebChannel

Migrating from QtWebKit to QtWebEngine, using QWebChannel. I have an invokable function that sends a QVariant Object to the Javascript, which is seen as a JSON object. So a QString becomes a string, a QInt an int, etc. Using QtWebKit without…
hereismass
  • 223
  • 1
  • 13
12
votes
6 answers

Is there a shorter way to initialize a QByteArray?

In my program I work a lot with serial communication so QByteArray is used very often. I was wondering if there was a shorter way to initialize a QByteArray with specific bytes than: const char test_data[] = { static_cast(0xB1),…
DBedrenko
  • 4,192
  • 3
  • 28
  • 66
12
votes
3 answers

How to convert QImage to QByteArray?

I am trying to create QByteArray from QImage, however although I tried lots of varient, I couldn't handle it. What I am doing is : QImage img_enrll; // <--- There is an image coming from another function. QByteArray…
goGud
  • 3,647
  • 7
  • 31
  • 58
12
votes
3 answers

Storing integer to QByteArray using only 4 bytes

It takes 4 bytes to represent an integer. How can I store an int in a QByteArray so that it only takes 4 bytes? QByteArray::number(..) converts the integer to string thus taking up more than 4 bytes. QByteArray((const char*)&myInteger,sizeof(int))…
Primož Kralj
  • 5,534
  • 14
  • 65
  • 125
12
votes
1 answer

qDebug isn't printing a full QByteArray containing binary data

I have a QByteArray to store data received from a GPS, which is part binary and part ASCII. I want to know for debug proposals know what's being received, so I'm writing a qDebug like this: //QByteArray buffer; //... qDebug() << "GNSS msg (" <<…
Roman Rdgz
  • 11,378
  • 36
  • 110
  • 192
10
votes
1 answer

Convert hexadecimal string to QByteArray

I need to convert a QString which is already in hexadecimal format to a QByteArray. For example: QString a = "AF5603B4" Should be stored in QByteArray as: QByteArray ba[4] = { 0xAF, 0x56, 0x03, 0xB4 } How do I do this in Qt 5.9? I have tried…
Abhishek Agarwal
  • 966
  • 1
  • 18
  • 31
10
votes
3 answers

Remove first bytes from QByteArray

I want to write a function in which QByteArray is input to the function. I want to remove some header from receive data and store it into global QByteArray. void abc::CopyData(const QByteArray &data) { switch(RequestPacketCount) { …
beparas
  • 1,787
  • 7
  • 21
  • 29
9
votes
1 answer

How to convert std::vector to QByteArray?

I am trying to create QByteArray from std::vector.. I tried; std::vector buf; QByteArray img = new QByteArray(reinterpret_cast(buf), buf.size()); However it gives error; error: invalid cast from type 'std::vector
goGud
  • 3,647
  • 7
  • 31
  • 58
9
votes
2 answers

Convert QByteArray to std::vector

I tried to convert QByteArray to std::vector using this code: unsigned char* buffer = (unsigned char*)byteArrayBuffer.constData(); std::vector::size_type size = strlen((const char*)buffer); std::vector
Jacob Krieg
  • 2,430
  • 10
  • 60
  • 114
8
votes
4 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
3 answers

Load QPixmap from QByteArray in Qt?

I have a byte array with the contents of an image (in png/bmp or some other format). How can I load it into a QPixmap?
user662285
  • 3,436
  • 22
  • 68
  • 100
8
votes
2 answers

What does QByteArray get converted to in QML?

If I have a signal: void foo(QByteArray data); And in QML I handle it: onFoo: { console.log(data.toString()); } What is the type of data in QML? What methods does it have? It doesn't seem to be a javascript string - it doesn't even have…
Timmmm
  • 68,359
  • 51
  • 283
  • 367
8
votes
2 answers

Convert unsigned char[10] to QBytearray;

I've seen a lot o questions around this, but so far none worked for me. I've tried the 2 most common answers but I get the same error. being but an unsigned char buf[10]; this, QByteArray databuf; databuf = QByteArray::fromRawData(buf, 10); or…
SamuelNLP
  • 3,583
  • 8
  • 50
  • 94
1
2 3
16 17