Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Int to char conversion

Int to char conversion

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 4 Posters 29.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ankit.k
    wrote on 24 Jan 2013, 12:17 last edited by
    #1

    The Ascii value of the characters should get the related character. I am searching for any function which does that, example for i=65, I get 'A'.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BelenMuñoz
      wrote on 24 Jan 2013, 12:29 last edited by
      #2

      I think it can be done with a cast.
      Something like that:

      char a = (char)i;

      Hope it works.

      Regards.

      Me casé con un enano pa jartarme de reí.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on 24 Jan 2013, 12:57 last edited by
        #3

        Look into using [[doc:QChar]].

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on 24 Jan 2013, 13:10 last edited by
          #4

          [quote author="BelenMuñoz" date="1359030558"]
          char a = (char)i;
          [/quote]

          This is a C style cast and in C++ code it is high recommend to use static_cast. Example:

          @
          int nMyInt = 65;
          char nMyChar = static_cast<char>(nMyInt);
          QChar char(nMyChar);
          @

          http://anavi.org/

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on 24 Jan 2013, 13:12 last edited by
            #5

            As QChar has a constructor that takes an int, the intermediary cast to char is not needed.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leon.anavi
              wrote on 24 Jan 2013, 13:17 last edited by
              #6

              [quote author="Andre" date="1359033121"]As QChar has a constructor that takes an int, the intermediary cast to char is not needed.[/quote]

              Yes, of course. I just wanted to highlight the recommended usage of static_cast instead of the C style cast :)

              http://anavi.org/

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on 24 Jan 2013, 13:19 last edited by
                #7

                I'd say that avoiding the cast altogether is preferable to a static_cast, which is preferable over a C style cast :-)

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  leon.anavi
                  wrote on 24 Jan 2013, 13:21 last edited by
                  #8

                  [quote author="Andre" date="1359033597"]I'd say that avoiding the cast altogether is preferable to a static_cast, which is preferable over a C style cast :-)[/quote]

                  (y) Absolutely :)

                  http://anavi.org/

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    BelenMuñoz
                    wrote on 24 Jan 2013, 14:54 last edited by
                    #9

                    [quote author="leon.anavi" date="1359033022"]
                    [quote author="BelenMuñoz" date="1359030558"]
                    char a = (char)i;
                    [/quote]

                    This is a C style cast and in C++ code it is high recommend to use static_cast. Example:

                    @
                    int nMyInt = 65;
                    char nMyChar = static_cast<char>(nMyInt);
                    QChar char(nMyChar);
                    @
                    [/quote]

                    Thanks for the reply, I still have bad habbits from C.

                    Me casé con un enano pa jartarme de reí.

                    1 Reply Last reply
                    1

                    1/9

                    24 Jan 2013, 12:17

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved