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 and c++ unicode escapes

QString and c++ unicode escapes

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.6k 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.
  • G Offline
    G Offline
    gkroeger
    wrote on last edited by
    #1

    Excuse my ignorance, but I can't figure out what is up with the following:

    @
    QString string 1 = new QString(" \u0394");
    @

    and

    @
    QString string 2 = new QString(" ");
    string2 += QChar(0x0394);
    @

    don't yield the same result. The latter is what I want (uppercase greek delta) but I can figure out what the first is doing?

    Thanks
    Glenn

    [EDIT: code formatting, Volker]

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      the fact is trivial.
      In the first case, you have an char* string which contains some bytes. this is different to utf16 (where the \oXXX makes sense). The string is converted to a QString by the loacle you use.

      This worked:

      @
      QString string1(" \u0394");
      QString string2(" ");
      string2 += QChar(0x0394);
      QString string3 = QString::fromWCharArray(L" \u0394");

      label_1->setText(string1);
      label_2->setText(string2);
      label_3->setText(string3);
      

      @

      Label 2 and 3 show the correct sign.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gkroeger
        wrote on last edited by
        #3

        Thanks Gerolf!

        My brain wasn't working so well this morning. As you point out, what is happening is obvious since the compiler replaces the literals before QString sees them.

        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