Results 1 to 2 of 2

Thread: Convert QString to unsigned char

  1. #1
    Join Date
    Jun 2011
    Posts
    23
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Convert QString to unsigned char

    Hi,

    I'm sure this is really easy but I just can't work out how to do it

    I have a QString which I need to put into

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

    Please note that tod is not a pointer (that seems easy to do). I have old-style-cast on so can't cast as (unsigned char). Using Qt5

    Thanks in advance!

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

    Default Re: Convert QString to unsigned char

    Usually an 8 bit character implies some 8 bit encodin, e.g. UTF-8 or Latin1.

    Use the respective encoding function and take the first byte of the resulting QByteArray, e.g.
    Qt Code:
    1. string.toUtf8()[0];
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. convert from unsigned char* to QString
    By bhaskar in forum Qt Programming
    Replies: 2
    Last Post: 12th February 2010, 06:36
  2. How to convert QString to std::string or char*?
    By yangyunzhao in forum Qt Programming
    Replies: 26
    Last Post: 26th August 2009, 06:52
  3. convert unsigned char * to QString
    By sepehr in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2008, 20:31
  4. How to convert QString to char *
    By rajeshs in forum Qt Programming
    Replies: 7
    Last Post: 27th September 2007, 10:32
  5. How to convert a QString to const char *?
    By SkripT in forum Newbie
    Replies: 2
    Last Post: 10th March 2006, 10:56

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.