Important: Please read the Qt Code of Conduct -

QString and c++ unicode escapes

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

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


    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?


    [EDIT: code formatting, Volker]

  • 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 2 and 3 show the correct sign.

  • 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.

Log in to reply