F
F
fowiv2019-10-21 17:22:45
Qt
fowiv, 2019-10-21 17:22:45

Convert character code from unicode to win1251?

Hello!
I get the character code through:
QString().number(c.id)
As a result, the character code in Unicode is obtained, for example, the Russian letter A will have a code of 1040, but 192 is needed in win1251.
How can this (QString().number(c.id)) string be converted to get character code 192 and not 1040?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ittakir, 2019-10-21
@fowiv

Use QTextCodec

QChar ch(1040);
QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
QByteArray result = codec->fromUnicode(&ch, 1);
unsigned char value = result[0]; // 192

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question