问题描述
我有在任何运行可以有不同长度的字符指针。例如:
I have a character pointer that in any run can have different length. For example:
char* myChar;
在一个运行其含量可的嗨的而在另一个运行它,可以的再见的
In one run its content can be "Hi" and in another run it can be "Bye".
我想 myChar
的内容复制到QString的,例如,如果我有:
I want to copy the content of myChar
to a QString, for example if I have:
QString myString;
我想 myChar
中的内容复制到的myString
;我该怎么办呢?
I want to copy the content of myChar
to myString
; how can I do that?
推荐答案
使用的QString :: fromLatin1(为const char *)
,的QString :: fromLocal8Bit(为const char *)
或的QString :: fromUtf8(为const char *)
为宜。请注意,你不能只是复制数据,因为将QString包含16位的Uni code字符。它总是需要去code中的8位重presentation。
Use QString::fromLatin1(const char*)
, QString::fromLocal8Bit(const char*)
or QString::fromUtf8(const char*)
as appropriate. Note that you can't just copy the data because QStrings contain 16-bit Unicode characters. It will always need to decode the 8-bit representation.
这篇关于字符数组的内容复制到Qt中为QString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!