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
4
votes
3 answers

Append a QByteArray to QDataStream?

I have to populate a QByteArray with different data. So I'm using the QDataStream. QByteArray buffer; QDataStream stream(&buffer, QIODevice::WriteOnly); qint8 dataHex= 0x04; qint8 dataChar = 'V'; stream << dataHex<< dataChar; qDebug() <<…
TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143
4
votes
2 answers

QFile to QByteArray save file name

I have a QFile that needs to be sent through a LAN network. In order to do so, I convert the QFile into QByteArray by doing: //! [Inside a QTcpSocket class] // Get the file name using a QFileDialog QFile file(QFileDialog::getOpenFileName(NULL,…
Alex Spataru
  • 1,197
  • 4
  • 14
  • 26
4
votes
2 answers

Convert from QByteArray to array of double

I have an array of double: QVector Y(count); I need to pack it to QByteArray to send via Ethernet. So I did it. It was not too hard: QByteArray line; line.clear(); line.append(QByteArray::fromRawData(reinterpret_cast
Dlash
  • 154
  • 3
  • 11
3
votes
1 answer

Read QByteArray setting written by QSetting within different Qt version.

QByteArray is serialized in different formats on the file system if the different version of Qt library is used (say 4.5.2 against 4.7.1). I use the QSettings in my application to store the some binary data in the .ini file. Now application is…
MedBrother
  • 31
  • 2
3
votes
1 answer

How to convert QByteArray to std::istream or std::ifstream?

I want to create istream from QByteArray at runtime, without saving a physical file in memory of QByteArray. I found that there are many ways to do the opposite conversion, i.e. istream to QByteArray, but not this one. How to accomplish that?
Sayan Bera
  • 135
  • 2
  • 16
3
votes
1 answer

PyQt5 save QByteArray to json format

This one is a pickle. I'm trying to save my window/other elements to json format so that I can have multiple data stored in 1 place for my window/etc I know that QByteArray has these functions: std::string QByteArray::toStdString()…
Dariusz
  • 960
  • 13
  • 36
3
votes
2 answers

can I access QtWebEngine's underlying IPC without QWebChannel?

QtWebEngine uses a IPC mechanism to communicate between the C+ Qt world and the JavaScript work. This mechanism is used for QWebChannel, and it appears to be based on WebSockets. Is there a way to use the underlying IPC or WebSockets without using…
3
votes
2 answers

Fill QByteArray from QAudioBuffer

My goal is to save a QAudioRecorder recording into memory. From my research it seems the best way to store the recording is to use a QByteArray. My audio recorder is probed using a QAudioProbe. From the audioBufferProbed signal I try to append the…
Alex
  • 361
  • 1
  • 4
  • 15
3
votes
3 answers

How to use Qt QSerialPort to send hex 0x00

I am new to coding. Please bear with me. I learnt from the Qt example Terminal and tried to send raw hex bytes. At first I could send 0x57, 0x04, 0x02 with no problem. Like this void MainWindow::writeData(const QByteArray &data) { …
DLiu
  • 53
  • 2
  • 6
3
votes
1 answer

Append multiple hex numbers to QByteArray simultaneously

I have bunch of hex numbers, but I don't feel like doing QByteArray ba; ba.append(0x01); ba.append(0x02); ba.append(0x7A); ... Can I do that in one line? Maybe with QString manipulation? I'm sending messages via serial communication QExtSerialPort…
jabk
  • 1,388
  • 4
  • 25
  • 43
3
votes
0 answers

What is the memory layout of a QByteArray

I am trying to find the memory layout of QByteArray (because I have to interface with a DLL, which has QByteArray as parameters). From the original QT sources, I extracted the following: template struct QGenericAtomicOps…
cskwg
  • 790
  • 6
  • 13
3
votes
2 answers

Qt-how to convert a QByteArray to struct

I need to convert a QByteArray to structure. I have a structure like this: struct mavlink_attitude_t { /// Timestamp (milliseconds since system boot) quint32 time_boot_ms; ///…
user4000670
3
votes
2 answers

How to send data from server to client as QByteArray/QDataStream

In the fortuneserver sample of Qt, a QString is sent by the method sendFortune(). Therefore one QString is selected from the QStringList fortunes: QByteArray block; QDataStream out(&block,…
3ef9g
  • 781
  • 2
  • 9
  • 19
3
votes
2 answers

Qt optimization of a QByteArray conversion

I wrote a function to convert a hexa string representation (like x00) of some binary data to the data itself. How to improve this code? QByteArray restoreData(const QByteArray &data, const QString prepender = "x") { QByteArray restoredData =…
Sylva1n
  • 119
  • 1
  • 7
3
votes
1 answer

QFile: how to efficiently read just bytes from k, to k+L

I can read bytes from k to k+L from QFile reading first whole file into QByteArray if (!file.open(QIODevice::ReadOnly)) //... QByteArray blob = file.readAll(); QByteArray bytes = blob.mid( k, L); How to read just bytes from k, to k+L,…
4pie0
  • 29,204
  • 9
  • 82
  • 118
1 2
3
17 18