简体   繁体   中英

Qt: Get ASCII Code From QChar

I need to get the ASCII code from a QChar .

In Qt 5.2 QChar::ToAscii has been removed.

Here is my code. How can I get the ASCII code?

QString data;
int key;
key = data.at(i);

Use:

char QChar::toLatin1() const

From the doc:

Returns the Latin-1 character equivalent to the QChar, or 0. This is mainly useful for non-internationalized software.

From a Qt5.0 version

char QChar::toAscii() const

This function is deprecated. Returns the Latin-1 character value of the QChar, or 0 if the character is not representable.

Example

QString test("test");
QChar c = test.at(0);
int v_latin = c.toLatin1();
int v_ascii = c.toAscii();
qDebug() << v_latin << " " << v_ascii;

Output:

116   116

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