PDA

View Full Version : Regarding qbytearray



mohanakrishnan
18th November 2009, 08:32
hi
im creating application to receive data from serial port.I have received data from the serial port, now i want to check the received hex decimal value...
for eg:
I am having the received data in qbytearray i need to check each byte of the array like below


QByteArray receiveddata;

if (receiveddata==0x7e)
{
//then do the following
}

The problem is ,in array ,the value is stored like below...
receiveddata[0]=7
receiveddata[1]=e ,but i need receiveddata[0]=0x7e
how to achieve this!!! any help is highly respected!!
thanks
:confused::confused:

spirit
18th November 2009, 08:48
maybe QByteArrayMatcher helps you.

mohanakrishnan
18th November 2009, 08:54
hi spirit
i ll try and revert back
thanks....::)

mohanakrishnan
18th November 2009, 10:18
hi
is there any better way to do this ...although qbytearraymatcher works..i need to check many
conditions like this
thanks.....:)

squidge
18th November 2009, 14:06
How about something like:



QByteArray foo;
quint8 receiveddata;

foo.append(7);
foo.append(14);

receiveddata = foo[0]<<4 | foo[1];

if (receiveddata == 0x7e)
{
...
}

mohanakrishnan
19th November 2009, 05:18
hi
i ll try as u said ,but my problem is ,i need to access received individual byte values....
so i need to check the bytes.So if it is as hexadecimal array ,so i can easily check..
i was able to do it in csharp...?? can it be done here???
thanks (now i ll try as u said)

:):confused:

mohanakrishnan
19th November 2009, 07:02
hi
it is working but if i use this my code will become very big....instead can i use char array to store and do the things....
thanks

squidge
19th November 2009, 13:38
Sure, but quint8 is char array:



typedef unsigned char quint8;