qtqstringqchar

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);
}

Solution

  • Thanks anyway. I found now the solution.

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

    :)