Results 1 to 12 of 12

Thread: QByteArray revisited

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QByteArray revisited

    Hi,

    I'm having problems extracting contents from a QByteArray...

    Given the code:
    Qt Code:
    1. QByteArray unitData;
    2. unitData=tcpSocket.readAll(); // incoming binary data
    3. .
    4. .
    5. .
    6. const char *c_str = unitData.toHex().data();
    7. cout << "Received: " << c_str << endl;
    To copy to clipboard, switch view to plain text mode 

    outputs correctly:
    000F353334...yacka yacka...
    but when one tries:
    Qt Code:
    1. void myUnit::checkImei (QByteArray &data)
    2. {
    3. bool ok;
    4. // check the # of bytes in the header
    5. unsigned int nbrBytes = data.left(2).toUInt(&ok,16);
    6. if (!ok) cout << "Conversion impossible!" << endl;
    7. cout << "# bytes: " << nbrBytes << endl;
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    number of bytes is *always* zero!

    Any pointers would be highly appreciated...
    Kind regards,
    Pedro Doria Meunier
    Last edited by jpn; 15th January 2008 at 12:21. Reason: reformatted to look better

Similar Threads

  1. QByteArray format
    By nowire75 in forum Newbie
    Replies: 1
    Last Post: 13th July 2007, 09:53
  2. QByteArray with network data
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2007, 17:53
  3. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 17:01
  4. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:23
  5. How to read a Number from the QByteArray
    By antonio.r.tome in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2006, 15:24

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
  •  
Qt is a trademark of The Qt Company.