Results 1 to 9 of 9

Thread: how to retrieve ascii code of a character in a qstring?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to retrieve ascii code of a character in a qstring?

    I'm trying to write an application with Qt 5.4, and I have to encode a string in code 128 barcode.
    So, the first character in the original string is byte 205 (Í):
    dummy is an int, risposta is the QString to encode

    dummy = (char) risposta.at(ind).toLatin1();

    dummy, in debug mode, becomes -51, and so, it makes me break following
    if (dummy < 127)
    dummy -= 32;
    else
    dummy -= 100;
    Anyone can help me?
    Gisac

  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: how to retrieve ascii code of a character in a qstring?

    If you want an intepretation as an unsigned number, use an unsigned type.

    Cheers,
    _

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

    gisac (26th May 2015)

  4. #3
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to retrieve ascii code of a character in a qstring?

    Unfortunately, if I declare
    uint dummy;
    and make:
    dummy=(char)risposta.at(ind).toLatin1();
    or
    dummy=(uint)risposta.at(ind).toLatin1();
    dummy becomes 4294967245!
    Help me, please!
    Thanks

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

    Default Re: how to retrieve ascii code of a character in a qstring?

    Qt Code:
    1. dummy=(unsigned char)risposta.at(ind).toLatin1();
    To copy to clipboard, switch view to plain text mode 

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

    gisac (26th May 2015)

  7. #5
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to retrieve ascii code of a character in a qstring?

    Just made! It's the same thing, dummy=-51 also with (unsigned char)!

  8. #6
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to retrieve ascii code of a character in a qstring?

    Quote Originally Posted by gisac View Post
    Just made! It's the same thing, dummy=-51 also with (unsigned char)!
    Actually, there is a strange behavior of qcreator: in the variable window, dummy continues to have the value -51, but in the following if it is considered to have value 205.
    Problem solved! thanks to all!

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

    Default Re: how to retrieve ascii code of a character in a qstring?

    You know that these are the basics of C / C ++? It has nothing to do with Qt.

  10. #8
    Join Date
    Nov 2014
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Windows

    Default Re: how to retrieve ascii code of a character in a qstring?

    Try this:

    string s = "hallo world";
    foreach( char c in s)
    {
    Console.WriteLine(System.Convert.ToInt32(c));
    }
    Console.ReadLine();

  11. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to retrieve ascii code of a character in a qstring?

    And just what does Java code have to do with either C++ or Qt?

Similar Threads

  1. Replies: 3
    Last Post: 2nd April 2012, 09:32
  2. QString checking whether in ASCII range
    By raj_iv in forum Qt Programming
    Replies: 2
    Last Post: 29th April 2011, 17:45
  3. retrieve code from DLL
    By kernel.roy in forum Qt Programming
    Replies: 1
    Last Post: 15th September 2010, 08:03
  4. Replies: 8
    Last Post: 14th April 2010, 05:54
  5. How to become int from code ASCII nummer?
    By patrik08 in forum Qt Programming
    Replies: 6
    Last Post: 3rd July 2006, 01:03

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.