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. QString encoding problem
Qt 6.11 is out! See what's new in the release blog

QString encoding problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.3k 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.
  • S Offline
    S Offline
    sonulohani
    wrote on last edited by sonulohani
    #1

    Hi,
    I have a code in Qt5 which looks like this:-

    QString str("âáéì");

    Whenever I am converting it to C++ std::string using toStdString(), Its giving me invalid characters. I have tried all encoding and its not working at all. I have my Qt built with ICU libs. Please help me in this regard.

    BTW if i print QString using qDebug() its printing ????

    T raven-worxR 2 Replies Last reply
    0
    • S sonulohani

      Hi,
      I have a code in Qt5 which looks like this:-

      QString str("âáéì");

      Whenever I am converting it to C++ std::string using toStdString(), Its giving me invalid characters. I have tried all encoding and its not working at all. I have my Qt built with ICU libs. Please help me in this regard.

      BTW if i print QString using qDebug() its printing ????

      T Offline
      T Offline
      Tikani
      wrote on last edited by
      #2

      @sonulohani
      What version of Qt5?

      1 Reply Last reply
      0
      • S sonulohani

        Hi,
        I have a code in Qt5 which looks like this:-

        QString str("âáéì");

        Whenever I am converting it to C++ std::string using toStdString(), Its giving me invalid characters. I have tried all encoding and its not working at all. I have my Qt built with ICU libs. Please help me in this regard.

        BTW if i print QString using qDebug() its printing ????

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @sonulohani
        the problem is when you insert it this way the default encoding from the compiler/file is taken. Which is most probably not what you want for special characters.

        Use the unicode escaping syntax to ensure the correct character data. e.g. "\uf02a" or whatever.

        @sonulohani said in QString encoding problem:

        Whenever I am converting it to C++ std::string using toStdString(), Its giving me invalid characters.

        how do you excactly check for those "invalid" characters?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        S 1 Reply Last reply
        2
        • raven-worxR raven-worx

          @sonulohani
          the problem is when you insert it this way the default encoding from the compiler/file is taken. Which is most probably not what you want for special characters.

          Use the unicode escaping syntax to ensure the correct character data. e.g. "\uf02a" or whatever.

          @sonulohani said in QString encoding problem:

          Whenever I am converting it to C++ std::string using toStdString(), Its giving me invalid characters.

          how do you excactly check for those "invalid" characters?

          S Offline
          S Offline
          sonulohani
          wrote on last edited by
          #4

          @raven-worx Hi, thanks for the answer. And if i get \u**** output, how do i convert it into the character.

          raven-worxR 1 Reply Last reply
          0
          • S sonulohani

            @raven-worx Hi, thanks for the answer. And if i get \u**** output, how do i convert it into the character.

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @sonulohani said in QString encoding problem:

            how do i convert it into the character.

            what do you mean?
            A "character" is just data. It just matters if you interpret it as a (Unicode-)character.
            Thats why i asked how you exactly check for those "invalid" characters?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            1

            • Login

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