How to cast a QChar to int

送分小仙女□ 提交于 2020-08-04 05:27:20

问题


In C++ there is a way to cast a char to int and get the ascii value in return. Is there such a way to do the same with a qchar? Since unicode supports so many characters and some of them are actually looking alike, it is sometimes hard to tell what one is dealing with. An explicit code point or a number that can be used to get such would be very helpful.

I searched a the web and this site for a solution but so far no luck, Qt documentation isn't much of help either, unless I'm overlooking something.

Thank you in advance!

EDIT:

Maybe I wasn't clear enough on the matter, sorry.

Here's some code:

char chChar = 'a';
cout << (int)chChar; // will output 97, not 'a'

Also, Qt allows this:

QChar ch = 'a';
if(ch == 0x61)
//...

As far as I can tell, there has to be some information relating to the unicode codepoint in the ch object. Any possibility to get it out of there?


回答1:


Took some time but I found the answer: QChar has a member named QChar::unicode which returns a ushort with its code point. Just for the record.




回答2:


You can try this:-

ch.toUpper() == QLatin1Char('S') ? 0LL : \

Check this reference.



来源:https://stackoverflow.com/questions/18364482/how-to-cast-a-qchar-to-int

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!