Qt:从QChar获取ASCII码

Mo3*_*3in 7 qt qchar

我需要从a获取ASCII码QChar.

在Qt 5.2中QChar::ToAscii已被删除.

这是我的代码.我怎样才能获得ASCII码?

QString data;
int key;
key = data.at(i);
Run Code Online (Sandbox Code Playgroud)

Kik*_*ohs 10

使用:

char QChar::toLatin1() const
Run Code Online (Sandbox Code Playgroud)

来自doc:

返回与QChar相当的Latin-1字符,或0.这对非国际化软件非常有用.

来自Qt5.0版本

char QChar::toAscii() const
Run Code Online (Sandbox Code Playgroud)

不推荐使用此功能.返回QChar的Latin-1字符值,如果字符不可表示,则返回0.

QString test("test");
QChar c = test.at(0);
int v_latin = c.toLatin1();
int v_ascii = c.toAscii();
qDebug() << v_latin << " " << v_ascii;
Run Code Online (Sandbox Code Playgroud)

输出:

116   116
Run Code Online (Sandbox Code Playgroud)