简体   繁体   中英

How can I convert QString to int for Unicodes? for QWSServer sendKeyEvent

how can I convert my QString composed of just one unicode to QChar and char?

I have this character cedilla. http://graphemica.com/%C3%A7

I don't have any idea yet about QChar but I tried using this code for converting QString to char.

char c[2];
strcpy(c, keyItem.contentText.toUtf8().constData());
printf("Character is: %c\n", c[0]);

but it shows this character

My 'keyItem' is a class and contentText returns a QString although there's only one character. When I try to return the usual letters I could read them right.

Update: I am trying to create a keyboard and I have to get the int value of the QString that's why I have to convert it to char first.

I will be using this to create the keyboard.

send(int(c[0]);
void send(int key){ 
    QWSServer::sendKeyEvent(key, key, 0, true, false);
}

Thanks anyway. I found now the solution.

QChar c;
c = keyItem.contentText[0];
send(c.unicode());

:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM