Results 1 to 2 of 2

Thread: converting qstring to unsigned char

  1. #1
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default converting qstring to unsigned char

    Hello every body,

    I am new to Qt and need to convert a qstring variable which is a Hex number to an unsinged char array type as you can see bellow

    Qt Code:
    1. QString str = "1234"; // which is the 0x1234 number
    To copy to clipboard, switch view to plain text mode 

    and I need to store it in one of the below data structure fields which is 2 byte (for instance the "unsigned char Base_Addrs[2]" field) :

    Qt Code:
    1. struct wrt_rqst_
    2. {
    3. unsigned char Dest_MAC[6];
    4. unsigned char Src_MAC[6];
    5. unsigned char Eth_Length[2];//should be 0x0800
    6. unsigned char Wrt_Cmd[2];//should be 0x0000
    7. unsigned char Base_Addrs[2];
    8. unsigned char Data_Length[2];//should be 0x02EB
    9. unsigned char data[1494];//should be set all az 0
    10.  
    11. }*wrt_buff;
    To copy to clipboard, switch view to plain text mode 

    how should I convert the qstring to unsigned char?

    Thanks.
    Last edited by havij000; 22nd July 2013 at 07:01.

  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: converting qstring to unsigned char

    Qt Code:
    1. int val = str.toInt(0, 16);
    To copy to clipboard, switch view to plain text mode 
    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.


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. unsigned char * to QString
    By elina.du in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2009, 08:33
  3. convert unsigned char * to QString
    By sepehr in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2008, 20:31
  4. QString to unsigned char *
    By darksaga in forum Qt Programming
    Replies: 9
    Last Post: 23rd July 2007, 07:52
  5. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10

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.