a universal character name specifies an invalid character with QT

Hi I'm trying to display the unicode keys to learn more about the topic. The Char contains the unicode as follows '\u0041'. It is a QString of the following "\u0041 " which I convert to char '\u0041'.Code:

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

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

 1
Author: Jorgesys, 2016-10-11

1 answers

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

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

So what I do is the following, in the switch I convert it to char for it to evaluate 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 this one works equally.

 0
Author: Sergio Ramos, 2016-10-11 22:53:59