a universal character name specifies a non-valid character with QT

1

Hi, I'm trying to show the unicode keys to learn more about the subject. The char contains the unicode as follows '\ u0041'. It is a QString of the following "\ u0041" that I convert to char '\ u0041'.Codigo:

char myChar = s[0].toLatin1(); // lo convierto en char

But when I put the code in the case:

 switch (myChar){
            // 
            case '\u0001': qDebug() << "aprendiendo";break;
            default:break;
        }

This is the error that gives me: a universal character name specifies an invalid character

Then it is impossible to show a unicode with a char, what code should I use. I want to learn to show it with a switch not with if.

    
asked by Sergio Ramos 11.10.2016 в 23:54
source

1 answer

0

Utf16 is for 2 bytes ie 16 bits whereas char is for 1 byte ie 8 bits. So which is the easiest way for me I use wchar_t which is for unicode, that is, a character that uses unicode, so I define it like this:

wchar_t myChar = s[0].unicode();

Then what I do is the following, in the switch I convert it to char so that it evaluates it and in case I use the character in unicode format:

switch ((char)myChar){
            // Number keys
            case '\u00C1': qDebug() << "0";break;
            default:break;
        }

There are other simpler ways, but it works equally.

    
answered by 12.10.2016 / 00:53
source