View Full Version : sending int array through socket
babu198649
20th December 2007, 07:20
hi
i have an int array which should be send through socket .
the problem is if i store the array in QByteArray(using setNum() and number() it takes one byte for every digit.
but i want to store any integer value in QByteArray as 4 bytes.
ie . each integer byte should be stored as a character in QByteArray
marcel
20th December 2007, 07:25
Are you sure QByteArray::number works like that?
If so, then maybe you will consider using my solution from your other post... It does just that - appends 4 bytes to the byte array( for 32 bit architectures, for 64 bit will append 8 bytes).
babu198649
20th December 2007, 07:31
ya i'm sure .
for ex:
QByteArray arr;
int i = 24558;
arr = arr.setNum(i);
qDebug()<<arr.size();
the output is 5
ex2:
QByteArray arr;
int i = 245;
arr = arr.setNum(i);
qDebug()<<arr.size();
the output is 3
jpn
20th December 2007, 07:39
Yes, that's what QByteArray::setNum() says it does. You might want to take a loot at QDataStream.
babu198649
20th December 2007, 07:59
hi jpn
actually i wnt an int arrray to send through the socket.
how to output the QDataStream to console
the following does not works
QDataStream stream;
int i=63;
stream <<i;
qDebug()<<stream;
is it possible to convert a QDataStream to QByteArray.
jpn
20th December 2007, 08:16
Open a data stream on the socket, just like many of the network examples (http://doc.trolltech.com/latest/examples.html#network) do.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.