Results 1 to 5 of 5

Thread: QString convert to QByteArray

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QString convert to QByteArray

    In case you want the numerical values in the string, see QString::toInt(), using a base of 16

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    schunyeh (28th January 2015)

  3. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: QString convert to QByteArray

    Read about QByteArray::fromHex

  4. The following user says thank you to Lesiok for this useful post:

    schunyeh (28th January 2015)

  5. #3
    Join Date
    Dec 2014
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    5

    Default Re: QString convert to QByteArray

    Thank jthomps,anda_skoa,Lesiok for the reply.
    The case is that I would like to input a text file that has a decimal number, and then got the numer to change them to the hexadecimal format ( 0xff), & write them to a special binary file format ( 008a 001a .... ..... ).
    After trying to convert, I have found the following API can do it.
    QString test_number; // "0x8a"
    QByteArray test_hex;
    test_hex = QByteArray::fromHex( test_number.toLocal8Bit().constData() );
    qDebug()<<test_hex.at(1); // 0x8a
    Thank you for the help.

Similar Threads

  1. how to convert an int to QByteArray
    By babu198649 in forum Qt Programming
    Replies: 12
    Last Post: 19th September 2014, 10:47
  2. Convert QPixmap to QByteArray ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2014, 09:23
  3. Replies: 10
    Last Post: 15th March 2011, 15:14
  4. convert QString to QByteArray
    By morgana in forum Qt Programming
    Replies: 5
    Last Post: 2nd March 2011, 14:33
  5. how can we convert QByteArray to Qstring?
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2009, 15:05

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.