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
Servers for Qt installer are currently down

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.
  • RIVOPICOR Offline
    RIVOPICOR Offline
    RIVOPICO
    wrote on 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....

    Paul ColbyP 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on 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
      • RIVOPICOR RIVOPICO

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

        Paul ColbyP Offline
        Paul ColbyP Offline
        Paul Colby
        wrote on 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.

        RIVOPICOR 1 Reply Last reply
        3
        • Paul ColbyP Paul Colby

          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.

          RIVOPICOR Offline
          RIVOPICOR Offline
          RIVOPICO
          wrote on last edited by RIVOPICO
          #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
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by VRonin
            #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

            • Login

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