gpt4 book ai didi

Qt:从 QChar 获取 ASCII 代码

转载 作者:行者123 更新时间:2023-12-01 18:25:57 28 4
gpt4 key购买 nike

我需要从 QChar 获取 ASCII 代码。

在 Qt 5.2 中,QChar::ToAscii 已被删除。

这是我的代码。如何获取 ASCII 码?

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

最佳答案

用途:

char QChar::toLatin1() const

来自文档:

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

从Qt5.0版本开始

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.

示例

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

关于Qt:从 QChar 获取 ASCII 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20841929/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com