sending int array through socket
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
Re: sending int array through socket
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).
Re: sending int array through socket
ya i'm sure .
for ex:
Code:
int i = 24558;
arr = arr.setNum(i);
qDebug()<<arr.size();
the output is 5
ex2:
Code:
int i = 245;
arr = arr.setNum(i);
qDebug()<<arr.size();
the output is 3
Re: sending int array through socket
Yes, that's what QByteArray::setNum() says it does. You might want to take a loot at QDataStream.
Re: sending int array through socket
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
Code:
int i=63;
stream <<i;
qDebug()<<stream;
is it possible to convert a QDataStream to QByteArray.
Re: sending int array through socket
Open a data stream on the socket, just like many of the network examples do.