Results 1 to 8 of 8

Thread: Regarding qbytearray

  1. #1
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Regarding qbytearray

    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
    Qt Code:
    1. QByteArray receiveddata;
    2.  
    3. if (receiveddata==0x7e)
    4. {
    5. //then do the following
    6. }
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Regarding qbytearray

    maybe QByteArrayMatcher helps you.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    mohanakrishnan (18th November 2009)

  4. #3
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Regarding qbytearray

    hi spirit
    i ll try and revert back
    thanks....:

  5. #4
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Regarding qbytearray

    hi
    is there any better way to do this ...although qbytearraymatcher works..i need to check many
    conditions like this
    thanks.....

  6. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Regarding qbytearray

    How about something like:

    Qt Code:
    1. quint8 receiveddata;
    2.  
    3. foo.append(7);
    4. foo.append(14);
    5.  
    6. receiveddata = foo[0]<<4 | foo[1];
    7.  
    8. if (receiveddata == 0x7e)
    9. {
    10. ...
    11. }
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Regarding qbytearray

    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)


  8. #7
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Regarding qbytearray

    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

  9. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Regarding qbytearray

    Sure, but quint8 is char array:

    Qt Code:
    1. typedef unsigned char quint8;
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. hex QByteArray to double?
    By tlt in forum Qt Programming
    Replies: 1
    Last Post: 12th July 2009, 03:33
  2. QByteArray problem
    By Misenko in forum Qt Programming
    Replies: 17
    Last Post: 4th October 2008, 21:53
  3. QByteArray with network data
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2007, 17:53
  4. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 17:01
  5. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.