我需要从 QChar
中获取 ASCII 码。
在 Qt 5.2 中,QChar::ToAscii
已被移除。
这是我的代码。我该如何获得 ASCII 码?
QString data;
int key;
key = data.at(i);
使用:
char QChar::toLatin1() const
来自文档:
返回与QChar等效的Latin-1字符,或0。这在非国际化软件中非常有用。
来自Qt5.0版本。
char QChar::toAscii() const
此函数已弃用。 返回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;
输出:
116 116