[SOLVED] Using Unsigned Char to store data from 0 - 255.
-
wrote on 12 Aug 2014, 17:37 last edited by
I am working on a system that has very low processing power and memory so trying to use unsigned chars to store values between 0 and 255. I need to capture a number using an unsigned char, send through a UDPSocket and then read the value on the other side. I have read numerous other posts and can’t find what I am doing wrong. Here is my code.
@
Unsigned char packetLength = ‘32’;
QByteArray dataByteArray;
dataByteArray.append(packetLength);QDataStream dataStream(&dataByteArray, QIODevice::ReadWrite);
dataByteArray << packetLength;
socket->writeDatagram(dataByteArray.data(), inMessage.size(), QHostAddress("101.1.1.103"), 1234);
@
It connects and transmits fine so on the other side I have this:
@
QDataStream qstr(&inPackets, QIODevice::ReadWrite);
Unsigned char packetL;
qstr >> packetL;
qDebug() >> packetL;
@
This prints a value of packet = 210. I am confused and think this should be easy. Any help is appreciated on how I can get the value 32 across. -
wrote on 12 Aug 2014, 17:53 last edited by
Please check out the use of "code wrappings":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01
I have introduced them for you this time.
-
wrote on 12 Aug 2014, 17:59 last edited by
Koahnig thank you. I just checked it out and will use it going forward.
-
wrote on 12 Aug 2014, 18:05 last edited by
That worked. I knew it had to be something simple. Much appreciated.
1/5