Results 1 to 2 of 2

Thread: Conversion from unsigned char* to unsigned char

  1. #1
    Join Date
    May 2007
    Posts
    110
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Conversion from unsigned char* to unsigned char

    hi

    in my application there is some error:cast from unsigned char* to unsigned char..

    how to convert unsigned char* to unsigned char.

    if anybody knows then reply

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Conversion from unsigned char* to unsigned char

    Well, that (unsigned char*) variable can be either a pointer to a single char or can be an array.
    Depends on how it is allocated.

    Anyway, you have to dereference it:
    Qt Code:
    1. unsigned char chr = 23;
    2. unsigned char* ptrChar = &chr; // pointer to a char
    3. unsigned char* arrayChar = new char[20]; //an array
    4. unsigned char valChar = *ptrChar; // now val char equals 23
    5. unsigned char firstChar = *arrayChar; //now firstChar equals arrayChar[0].
    To copy to clipboard, switch view to plain text mode 
    So, everything depends on how the pointer was allocated.

    BTW, I think you should have posted in the general programming forum.

    Regards

Similar Threads

  1. QString to unsigned char *
    By darksaga in forum Qt Programming
    Replies: 9
    Last Post: 23rd July 2007, 07:52
  2. unable to save QCStrings properly in a buffer
    By nass in forum Qt Programming
    Replies: 13
    Last Post: 15th November 2006, 20:49

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.