Results 1 to 2 of 2

Thread: QTextStream and hex data

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2009
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextStream and hex data

    I want to read hex data from a QTextStream
    Qt Code:
    1. #include <QTextStream>
    2. int main(int, char**) {
    3. QString string("hexvalue 7C00 15");
    4. QTextStream in(&string);
    5. in.setIntegerBase(16);
    6. QString str1, str2;
    7. unsigned int val1;
    8. in >> str1 >> val1 >> str2;
    9. qDebug("%s %x %s", qPrintable(str1), val1, qPrintable(str2));
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 
    This program outputs
    Qt Code:
    1. hexvalue 0 C00
    To copy to clipboard, switch view to plain text mode 
    I thought that setIntegerBase(16) tells the stream to expect hex input when reading integers. The read stops on the character C, whic becomes p[art of a following string.

    Can I read a hex value without reading a string and then converting and without a 0x prefix ?
    All ideas welcome

    Enno

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTextStream and hex data

    Don't think there is any other way than reading as string and then to number.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. QTextStream
    By weixj2003ld in forum Qt Programming
    Replies: 5
    Last Post: 10th September 2012, 15:09
  2. QTextStream
    By lahmitia in forum Qt Programming
    Replies: 3
    Last Post: 8th March 2011, 21:50
  3. QTextStream
    By WXNSNW in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2008, 16:43
  4. Replies: 4
    Last Post: 8th January 2008, 18:41
  5. QTextStream help pls
    By munna in forum Newbie
    Replies: 5
    Last Post: 16th May 2006, 18:45

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.