Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
通过以下方式可以很容易地将字符串转换为 a QTextCodec *:
QTextCodec *
char *str = "UTF-8"; QTextCodec *codec = QTextCodec::codecForName(str);
但是我们可以反过来吗?例如:
QTextCodec *codec = QTextCodec::codecForName("System");
但是我怎样才能codec变成一个字符串,以便我知道编码系统是 UTF-8/UTF-16 或其他?
codec
但是如何将编解码器转换为字符串,以便我知道编码系统是 UTF-8/UTF-16 或其他?
通过使用QTextCodec::name() const.
QTextCodec::name() const
char *str = "UTF-8"; QTextCodec *codec = QTextCodec::codecForName(str); QByteArray name = codec->name(); // "UTF-8"