Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Show QLatin1String concat of Unicode QString in a single string

    General and Desktop
    qstring qlatin1string unicode character encod
    2
    6
    2185
    Loading More Posts
    • 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
      KanishkaW last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • K
          KanishkaW last edited by

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

          Thanks.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • K
              KanishkaW @SGaist last edited by

              @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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 0
                • First post
                  Last post