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. Show QLatin1String concat of Unicode QString in a single string
QtWS25 Last Chance

Show QLatin1String concat of Unicode QString in a single string

Scheduled Pinned Locked Moved General and Desktop
qstringqlatin1stringunicodecharacter encod
6 Posts 2 Posters 2.8k 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.
  • K Offline
    K Offline
    KanishkaW
    wrote on last edited by
    #1

    I know the title is a bit confusing, even I don't know how to summarize it. Here is the issue.

    I have two strings, one is an Extended ASCII (can be represented using QLatin1String) and a Unicode String (can be represented by a QString).

    I am combining them using QString::arg() method as below.

    QLatin1String latinStr = "Adiós";
    QString unicodeStr = "some Uniocode හාහාහා %1";
    
    QString newStr = unicodeStr.arg(latinStr);
    

    Now this newStr has my concatenated string. If I print newStr, it prints "?" for the extended ASCII. If I convert the newStr to a QLatin1String using QString::fromLatin1(), the unicode part shows in a weird way.

    Is there any way to solve this?

    PS : I already have posted this in StackOverflow, but haven't got any solution yet.
    (http://stackoverflow.com/questions/32002281/show-qlatin1string-concat-of-unicode-qstring-in-a-single-string)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Are you by any chance using Qt 5.5 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KanishkaW
        wrote on last edited by
        #3

        No, I'm using Qt 5.2.
        Is there any workaround in Qt 5.5 ?

        Thanks.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Sorry, I have mixed your problem with another one. In any case isn't ó unicode rather than Latin1 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          K 1 Reply Last reply
          0
          • SGaistS SGaist

            Sorry, I have mixed your problem with another one. In any case isn't ó unicode rather than Latin1 ?

            K Offline
            K Offline
            KanishkaW
            wrote on last edited by
            #5

            @SGaist It can be either Unicode or Extended ASCIIm depending on the encoding used when creating the character. For the moment, let's assume that it is Extended ASCII.

            If so, what can be the remedy?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I wouldn't assume that.

              QLatin1String latinStr("Adiós");
              qDebug() << latinStr << newStr;
              

              Gives:

              "Adi\u00C3\u00B3s"
              

              A workaround that you can try:

               QString unicodeStr = "some Uniocode හාහාහා %1";
               QString newStr = unicodeStr.arg(QString::fromUtf8(latinStr.data()));
               qDebug() << newStr;
              

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

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