Results 1 to 7 of 7

Thread: storing data in hexadecimal format

  1. #1
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default storing data in hexadecimal format

    hii....
    i want to store data into file in hexadecimal format.

    How can it be done ?

    Follwing is the code I tried :

    Qt Code:
    1. QFile fileC("test_1.hex");
    2. QTextStream outC(&fileC);
    3.  
    4.  
    5. unsigned char cData = 47;
    6. outC << cData;l
    To copy to clipboard, switch view to plain text mode 

    The code writes 47,but in Char Format.How can we conver it into hexadecimal

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: storing data in hexadecimal format

    Don't use QTextStream. Use QFile::write() instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    aj2903 (12th January 2010)

  4. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: storing data in hexadecimal format

    if you want to store a single character, see QString::arg(), there are overloads that let you specify the base (choose 16 for hex). If you have more data, QByteArray::toHex() might interest you as well.

    HTH

  5. The following user says thank you to caduel for this useful post:

    aj2903 (12th January 2010)

  6. #4
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: storing data in hexadecimal format

    Qt Code:
    1. outC << showbase << hex << uppercasebase << uppercasedigits << cData;
    To copy to clipboard, switch view to plain text mode 

  7. #5
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: storing data in hexadecimal format

    thanks for replying
    but still not able to get it right.

    can someone display code snippet for the same

  8. #6
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: storing data in hexadecimal format

    thanks for replying
    but still not able to get it right.

    can someone display code snippet for the same

  9. #7
    Join Date
    Sep 2009
    Location
    Finland
    Posts
    63
    Thanks
    1
    Thanked 22 Times in 19 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: storing data in hexadecimal format

    How about using QDataStream instead of QTextStream? QDataStream provides a serialization of binary data. The examples of data/text stream are part of the documentation.

  10. The following user says thank you to tsp for this useful post:

    aj2903 (13th January 2010)

Similar Threads

  1. Replies: 1
    Last Post: 3rd December 2009, 09:20
  2. how to process hexadecimal
    By mohanakrishnan in forum Qt Programming
    Replies: 2
    Last Post: 20th November 2009, 04:33
  3. How can you display binary data in hex format?
    By Cruz in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2009, 14:40
  4. Defining data format in c++
    By locus in forum General Programming
    Replies: 3
    Last Post: 13th April 2007, 19:40
  5. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17

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.