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 Utf8 and latin1 difference

QString Utf8 and latin1 difference

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.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.
  • A Offline
    A Offline
    Abhi_oct30
    wrote on last edited by
    #1

    Hi,

    I am using QT-5.
    I have used the below code:
    QString str1= QString::fromLatin1("abc÷ßàéöø");
    QString str= QString::fromUtf8("abc÷ßàéöø");
    if (str1==str)
    ui->textEdit_2->setText("true");
    else
    ui->textEdit_2->setText("false");

    This always results in false.
    Why is it like this?
    Internally QString should be in same format,its character pointer which have different format,for which we use fromLatin1 or fromUtf8.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      In fact you test the encoding of your source editor.

      Results of str and str1 with utf8 or Latin1 encodings set in QtCreator:
      "abc������" "abc÷ßàéöø" -> latin1
      "abc÷ßàéöø" "abc÷Ã\u009Fà éöø" -> utf8

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Abhi_oct30
        wrote on last edited by
        #3

        Does this mean that latin1 and utf8 strings which are converted from character pointers won't be same if it's having extended acsii characters?

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

          "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