Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Convert char to QString
Forum Updated to NodeBB v4.3 + New Features

Convert char to QString

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 31.2k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RIVOPICO
    wrote on 5 Oct 2016, 21:48 last edited by
    #1

    Sorry for this maybe but how i can convert a char to QString? i was searching and i tried but i couldnt....

    P 1 Reply Last reply 5 Oct 2016, 22:08
    0
    • V Offline
      V Offline
      VRonin
      wrote on 5 Oct 2016, 22:06 last edited by
      #2

      QString test(QChar('a'));

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • R RIVOPICO
        5 Oct 2016, 21:48

        Sorry for this maybe but how i can convert a char to QString? i was searching and i tried but i couldnt....

        P Offline
        P Offline
        Paul Colby
        wrote on 5 Oct 2016, 22:08 last edited by
        #3

        Hi @RIVOPICO,

        how i can convert a char to QString?

        There's lots of ways, and it really depends on how your char is encoded. For example, if its a simple ASCII / Latin1 char, then one option is to use QChar, such as:

        const char c = 'C';
        qDebug() << QString(QChar::fromLatin1(c));
        

        Or, for example, if you mean a char * to a string of characters, then it may be appropriate to use QString::fromLocal8Bit()

        const char * const str = "STR";
        qDebug() << QString::fromLocal8Bit(str);
        

        Cheers.

        R 1 Reply Last reply 5 Oct 2016, 22:10
        3
        • P Paul Colby
          5 Oct 2016, 22:08

          Hi @RIVOPICO,

          how i can convert a char to QString?

          There's lots of ways, and it really depends on how your char is encoded. For example, if its a simple ASCII / Latin1 char, then one option is to use QChar, such as:

          const char c = 'C';
          qDebug() << QString(QChar::fromLatin1(c));
          

          Or, for example, if you mean a char * to a string of characters, then it may be appropriate to use QString::fromLocal8Bit()

          const char * const str = "STR";
          qDebug() << QString::fromLocal8Bit(str);
          

          Cheers.

          R Offline
          R Offline
          RIVOPICO
          wrote on 5 Oct 2016, 22:10 last edited by RIVOPICO 10 May 2016, 22:11
          #4

          @VRonin and in qt can be used normal strings like c++. I checked and you can create normal char like c++. What is better QChar or char, strings i couldnt only qstrings. and i am using normal char??

          1 Reply Last reply
          0
          • V Offline
            V Offline
            VRonin
            wrote on 5 Oct 2016, 22:13 last edited by VRonin 10 May 2016, 22:27
            #5

            QChar supports unicode, char supports only ascii

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            3

            1/5

            5 Oct 2016, 21:48

            • Login

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