使用UTF-8或Latin1编码将QString转换为QByteArray [英] Convert QString into QByteArray with either UTF-8 or Latin1 encoding
问题描述
我想隐藏一个QString到utf8或latin1 QByteArray,
,但今天我得到的一切utf8。
我测试这个在latin1高于0x7f,
的高段中的一些char,其中德国ü是一个很好的例子。
如果我这样做:
QString名称(\\\ü) ; // U + 00FC =ü
QByteArray utf8;
utf8.append(name);
qDebug()<< utf8<名称<< utf8.toHex();
QByteArray latin1;
latin1.append(name.toLatin1());
qDebug()<< Latin1<名称<< latin1.toHex();
QTextCodec * codec = QTextCodec :: codecForName(ISO 8859-1);
QByteArray encodedString = codec-> fromUnicode(name);
qDebug()<< ISO 8859-1<<名称<< encodedString.toHex();
我得到以下输出。
utf8üc3bc
Latin1üc3bc
ISO 8859-1üc3bc
正如你可以看到,我得到unicode 0xc3bc无处不在,我希望得到Latin1 0xfc步骤2和3。
我的猜测是,我应该得到这样的:
utf8ü c3bc
Latin1üfc
ISO 8859-1üfc
这是怎么回事?
/感谢
b $ b
链接到某些字符表:
- http://www.utoronto.ca/web/HTMLdocs/NewHTML/iso_table.html
- http://www.utf8-zeichentabelle.de/
< hr>
此代码是在基于Ubuntu 10.04的系统上构建和执行的。
$> uname -a
Linux frog 2.6.32-28-generic-pae#55-Ubuntu SMP Mon Jan 10 22:34:08 UTC 2011 i686 GNU / Linux
$> env | grep LANG
LANG = en_US.utf8
如果我尝试使用
utf8append(name.toUtf8());
我得到这个输出
utf8üc383c2bc
Latin1üc3bc
ISO 8859-1üc3bc
所以latin1是unicode,utf8是双重编码的...
在某些系统设置上?
如果我运行这个(无法获取。 >
qDebug()< system name:< QLocale :: system()。name();
qDebug()<< codecForCStrings:< QTextCodec :: codecForCStrings();
qDebug()<< codecForLocale:< QTextCodec :: codecForLocale() - > name();
然后我得到这个:
系统名称:en_US
codecForCStrings:0x0
codecForLocale:System
解决方案
如果我指定为UTF -8我使用所以不同的类知道这个,
然后它工作。QTextCodec :: setCodecForLocale QTextCodec :: codecForName(UTF-8));
QTextCodec :: setCodecForCStrings(QTextCodec :: codecForName(UTF-8));
qDebug()<< system name:< qLocale :: system()。name();
qDebug()<< codecForCStrings:< QTextCodec :: codecForCStrings() - > name();
qDebug()<< codecForLocale:< QTextCodec :: codecForLocale() - > name();
QString名称(\\\ü);
QByteArray utf8;
utf8.append(name);
qDebug()<< utf8<名称<< utf8.toHex();
QByteArray latin1;
latin1.append(name.toLatin1());
qDebug()<< Latin1<名称<< latin1.toHex();
QTextCodec * codec = QTextCodec :: codecForName(latin1);
QByteArray encodedString = codec-> fromUnicode(name);
qDebug()<< ISO 8859-1<<名称<< encodedString.toHex();
然后我得到这个输出:
系统名称:en_US
codecForCStrings:UTF-8
codecForLocale:UTF-8
utf8üc3bc
Latin1üfc
ISO 8859-1üfc
$ p
<
- 执行字元页
C ++标准,这是描述字符串和字符文字在编译器产生的二进制文件中的输出的术语。您可以在 1的 1.1字符集子部分中阅读 http://gcc.gnu.org 网站上的
问题:
由于\\\ü
字符串字面量?
回答:
这取决于执行字符集是什么。在gcc(这是你正在使用的)的情况下,它的默认值为UTF-8,除非你指定与 -fexec-charset
选项不同。您可以在 3.11控制预处理程序的选项中了解此选项和控制预处理阶段的其他选项。 http://gcc.gnu上的 GCC手册中的 3 GCC命令选项 .org 网站。现在当我们知道执行字符集是UTF-8时,我们知道\\\ü
将被转换为 U + 00FC
Unicode的代码点,它是两个字节的序列 0xc3 0xbc
。
QString的构造函数采用 char *
调用 QString QString :: fromAscii(const char * str,int size = -1)
它使用void QTextCodec :: setCodecForCStrings(QTextCodec * codec)
(如果已设置任何编解码器)或做同样的事情作为 QString QString :: fromLatin1(const char * str,int size = -1)
问题:
将使用哪种编解码器通过QString的构造函数来解码两个字节序列( 0xc3 0xbc
)它会得到什么?
回答:
默认情况下,没有使用 QTextCodec :: setCodecForCStrings()
这就是为什么Latin1将用于解码字节序列。因为 0xc3
和 0xbc
都在拉丁语1中有效,分别表示Ã和¼因为它是直接从这个答案你早先的问题),我们得到QString这两个字符。
-
qDebug()
不是8位清除
您不应使用 QDebug
类输出 ASCII 之外的任何内容。
测试程序:
#include< QtCore>
void dbg(char const * rawInput,QString s){
QString codepoints;
foreach(QChar chr,s){
codepoints.append(QString :: number(chr.unicode(),16))。append();
}
qDebug()<< 输入:< rawInput
<< ,
<< Unicode codepoints:<编码点
}
int main(int argc,char * argv [])
{
QCoreApplication app(argc,argv);
qDebug()<< system name:
<< QLocale :: system()。name();
for(int i = 1; i <= 5; ++ i){
switch(i){
case 1:
qDebug()<< \\\
Without codecForCStrings(默认为Latin1)\\\
;
break;
case 2:
qDebug()<< \\\
With codecForCStrings设置为UTF-8 \\\
;
QTextCodec :: setCodecForCStrings(QTextCodec :: codecForName(UTF-8));
break;
case 3:
qDebug()<< \\\
Without codecForCStrings(默认为Latin1),codecForLocale设置为UTF-8 \\\
;
QTextCodec :: setCodecForCStrings(0);
QTextCodec :: setCodecForLocale(QTextCodec :: codecForName(UTF-8));
break;
case 4:
qDebug()<< \\\
Without codecForCStrings(默认为Latin1),codecForLocale设置为Latin1 \\\
;
QTextCodec :: setCodecForCStrings(0);
QTextCodec :: setCodecForLocale(QTextCodec :: codecForName(Latin1));
break;
}
qDebug()<< codecForCStrings:< (QTextCodec :: codecForCStrings()
?QTextCodec :: codecForCStrings() - > name()
:NOT SET);
qDebug()<< codecForLocale:< (QTextCodec :: codecForLocale()
?QTextCodec :: codecForLocale() - > name()
:NOT SET);
qDebug()<< \\\
1。Using QString :: QString(char const *);
dbg(\\\\ü,QString(\\\ü));
dbg(\\xc3\\xbc,QString(\xc3\xbc));
dbg(LATIN SMALL LETTER U WITH DIAERESIS,QString(ü));
qDebug()<< \\\
2。Using QString :: fromUtf8(char const *);
dbg(\\\\ü,QString :: fromUtf8(\\\ü));
dbg(\\xc3\\xbc,QString :: fromUtf8(\xc3\xbc));
dbg(LATIN SMALL LETTER U WITH DIAERESIS,QString :: fromUtf8(ü));
qDebug()<< \\\
3。Using QString :: fromLocal8Bit(char const *);
dbg(\\\\ü,QString :: fromLocal8Bit(\\\ü));
dbg(\\xc3\\\xbc,QString :: fromLocal8Bit(\xc3\xbc));
dbg(LATIN SMALL LETTER U WITH DIAERESIS,QString :: fromLocal8Bit(ü));
}
return app.exec();
}
Windows XP上的mingw 4.4.0上的输出:
系统名称:pl_PL
没有codecForCStrings(默认是Latin1)
codecForCStrings: NOT SET
codecForLocale:System
1.使用QString :: QString(char const *)
输入:\\\ü,Unicode codepoints:c3 bc
输入:\ xc3 \xbc,Unicode代码点:c3 bc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fc
2.使用QString :: fromUtf8(char const *)
输入:\\\ü,Unicode codepoints:fc
输入:\xc3\xbc,Unicode codepoints:fc
输入:LATIN小写字母U和DIAERESIS,Unicode编码点:fffd
3.使用QString :: fromLocal8Bit(char const *)
输入:\\\ü,Unicode codepoints:102 13d
输入:\ xc3 \xbc,Unicode代码点:102 13d
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fc
将codecForCStrings设置为UTF-8
codecForCStrings:UTF-8
codecForLocale:System
1.使用QString :: QString(char const *)
输入:\\\ü,Unicode codepoints:fc
输入:\xc3\xbc,Unicode代码点:fc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fffd
2.使用QString :: fromUtf8(char const *)
输入:\\\ü,Unicode codepoints:fc
输入:\xc3 \xbc, Unicode代码点:fc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fffd
3.使用QString :: fromLocal8Bit(char const *)
输入:\\\ü,Unicode代码点:102 13d
输入:\xc3\xbc,Unicode代码点:102 13d
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fc
没有codecForCStrings(默认是Latin1),codecForLocale设置为UTF-8
codecForCStrings:NOT SET
codecForLocale:UTF-8
1.使用QString :: QString(char const *)
输入:\\\ü,Unicode codepoints:c3 bc
输入:\xc3\xbc,Unicode codepoints:c3 bc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fc
2.使用QString :: fromUtf8(char const *)
输入:\\\ü,Unicode codepoints:fc
输入:\xc3\xbc,Unicode代码点:fc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fffd
3.使用QString :: fromLocal8Bit(char const *)
输入:\\\ü,Unicode codepoints:fc
输入:\xc3\xbc,Unicode codeepoint :fc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fffd
没有codecForCStrings(默认是Latin1),codecForLocale设置为Latin1
codecForCStrings:NOT SET
codecForLocale:ISO-8859-1
1.使用QString :: QString(char const *)
输入:\\\ü ,Unicode代码点:c3 bc
输入:\xc3\xbc,Unicode代码点:c3 bc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fc
2.使用QString :: fromUtf8(char const *)
输入:\\\ü,Unicode codepoints:fc
输入:\xc3\xbc,Unicode codepoints: fc
输入:LATIN SMALL LETTER U with DIAERESIS,Unicode codepoints:fffd
3.使用QString :: fromLocal8Bit(char const *)
输入:\\\ü ,Unicode代码点:c3 bc
输入:\xc3\xbc,Unicode代码点:c3 bc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fc
codecForCStrings:NOT SET
codecForLocale:ISO-8859-1
1.使用QString :: QString(char const *)
输入:\\\ü, Unicode代码点:c3 bc
输入:\xc3 \xbc,Unicode代码点:c3 bc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fc
2.使用QString :: fromUtf8(char const *)
输入:\\\ü,Unicode codepoints:fc
输入:\xc3\xbc,Unicode codepoints:fc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fffd
3.使用QString :: fromLocal8Bit(char const *)
输入:\\\ü, Unicode代码点:c3 bc
输入:\xc3 \xbc,Unicode代码点:c3 bc
输入:LATIN SMALL LETTER U WITH DIAERESIS,Unicode codepoints:fc
thiago , cbreak , peppe 和 heinz 从#qt freenode.org IRC频道显示并帮助我了解此处涉及的问题。
I would like to covert a QString into either a utf8 or a latin1 QByteArray,
but today I get everything as utf8.
And I am testing this with some char in the higher segment of latin1 higher than 0x7f,
where the german ü is a good example.
If I do like this:
QString name("\u00fc"); // U+00FC = ü
QByteArray utf8;
utf8.append(name);
qDebug() << "utf8" << name << utf8.toHex();
QByteArray latin1;
latin1.append(name.toLatin1());
qDebug() << "Latin1" << name << latin1.toHex();
QTextCodec *codec = QTextCodec::codecForName("ISO 8859-1");
QByteArray encodedString = codec->fromUnicode(name);
qDebug() << "ISO 8859-1" << name << encodedString.toHex();
I get the following output.
utf8 "ü" "c3bc"
Latin1 "ü" "c3bc"
ISO 8859-1 "ü" "c3bc"
As you can see I get the unicode 0xc3bc everywhere, where I would expect to get the Latin1 0xfc for step 2 and 3.
My guess is that I should get something like this:
utf8 "ü" "c3bc"
Latin1 "ü" "fc"
ISO 8859-1 "ü" "fc"
What is going on here?
/Thanks
Links to some character tables:
This code was build and executed on a Ubuntu 10.04 based system.
$> uname -a
Linux frog 2.6.32-28-generic-pae #55-Ubuntu SMP Mon Jan 10 22:34:08 UTC 2011 i686 GNU/Linux
$> env | grep LANG
LANG=en_US.utf8
And if I try to use
utf8.append(name.toUtf8());
I get this output
utf8 "ü" "c383c2bc"
Latin1 "ü" "c3bc"
ISO 8859-1 "ü" "c3bc"
So the latin1 is unicode and the utf8 is double encoded...
This must depend on some system settings?
If I run this (could not get the .name() to build)
qDebug() << "system name:" << QLocale::system().name();
qDebug() << "codecForCStrings:" << QTextCodec::codecForCStrings();
qDebug() << "codecForLocale:" << QTextCodec::codecForLocale()->name();
Then I get this:
system name: "en_US"
codecForCStrings: 0x0
codecForLocale: "System"
Solution
If I specify that it is UTF-8 I am using so the different classes know about this,
then it works.
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
qDebug() << "system name:" << QLocale::system().name();
qDebug() << "codecForCStrings:" << QTextCodec::codecForCStrings()->name();
qDebug() << "codecForLocale:" << QTextCodec::codecForLocale()->name();
QString name("\u00fc");
QByteArray utf8;
utf8.append(name);
qDebug() << "utf8" << name << utf8.toHex();
QByteArray latin1;
latin1.append(name.toLatin1());
qDebug() << "Latin1" << name << latin1.toHex();
QTextCodec *codec = QTextCodec::codecForName("latin1");
QByteArray encodedString = codec->fromUnicode(name);
qDebug() << "ISO 8859-1" << name << encodedString.toHex();
Then I get this output:
system name: "en_US"
codecForCStrings: "UTF-8"
codecForLocale: "UTF-8"
utf8 "ü" "c3bc"
Latin1 "ü" "fc"
ISO 8859-1 "ü" "fc"
And that looks like it should.
解决方案 Things to know:
- execution character page
There's something called execution character set in the C++ standard which is the term that describes what the output of string and character literals will be in the binary produced by compiler. You can read about it in the 1.1 Character sets subsection of 1 Overview section in The C Preprocessor's Manual on http://gcc.gnu.org site.
Question:
What will be produced as a result of "\u00fc"
string literal?
Answer:
It depends on what the execution character set is. In case of gcc (which is what you're using) it's by default UTF-8 unless you specify something different with -fexec-charset
option. You can read about this and other options controlling preprocessing phase in the 3.11 Options Controlling the Preprocessor subsection of 3 GCC Command Options section in GCC's Manual on http://gcc.gnu.org site. Now when we know that execution character set is UTF-8 we know that "\u00fc"
will be translated to UTF-8 encoding of U+00FC
Unicode's code point which is a sequence of two bytes 0xc3 0xbc
.
QString::QString ( const char * str )
and QByteArray & QByteArray::append ( const QString & str )
depend on global state
The QString's constructor taking char *
calls QString QString::fromAscii ( const char * str, int size = -1 )
which uses codec set with void QTextCodec::setCodecForCStrings ( QTextCodec * codec )
(if any codec had been set) or does the same thing as QString QString::fromLatin1 ( const char * str, int size = -1 )
(in case no codec had been set).
Question:
What codec will be used by QString's constructor to decode two byte sequence (0xc3 0xbc
) it gets?
Answer:
By default no codec is set with QTextCodec::setCodecForCStrings()
that's why Latin1 will be used to decode byte sequence. As 0xc3
and 0xbc
are both valid in Latin 1, representing respectively à and ¼ (this should already be familiar to you as it was taken directly from this answer to your earlier question) we get QString with these two characters.
qDebug()
is not 8-bit clean
You shouldn't use QDebug
class to output anything outside of ASCII. You have no guarantee what you get.
Test program:
#include <QtCore>
void dbg(char const * rawInput, QString s) {
QString codepoints;
foreach(QChar chr, s) {
codepoints.append(QString::number(chr.unicode(), 16)).append(" ");
}
qDebug() << "Input: " << rawInput
<< ", "
<< "Unicode codepoints: " << codepoints;
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
qDebug() << "system name:"
<< QLocale::system().name();
for (int i = 1; i <= 5; ++i) {
switch(i) {
case 1:
qDebug() << "\nWithout codecForCStrings (default is Latin1)\n";
break;
case 2:
qDebug() << "\nWith codecForCStrings set to UTF-8\n";
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
break;
case 3:
qDebug() << "\nWithout codecForCStrings (default is Latin1), with codecForLocale set to UTF-8\n";
QTextCodec::setCodecForCStrings(0);
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
break;
case 4:
qDebug() << "\nWithout codecForCStrings (default is Latin1), with codecForLocale set to Latin1\n";
QTextCodec::setCodecForCStrings(0);
QTextCodec::setCodecForLocale(QTextCodec::codecForName("Latin1"));
break;
}
qDebug() << "codecForCStrings:" << (QTextCodec::codecForCStrings()
? QTextCodec::codecForCStrings()->name()
: "NOT SET");
qDebug() << "codecForLocale:" << (QTextCodec::codecForLocale()
? QTextCodec::codecForLocale()->name()
: "NOT SET");
qDebug() << "\n1. Using QString::QString(char const *)";
dbg("\\u00fc", QString("\u00fc"));
dbg("\\xc3\\xbc", QString("\xc3\xbc"));
dbg("LATIN SMALL LETTER U WITH DIAERESIS", QString("ü"));
qDebug() << "\n2. Using QString::fromUtf8(char const *)";
dbg("\\u00fc", QString::fromUtf8("\u00fc"));
dbg("\\xc3\\xbc", QString::fromUtf8("\xc3\xbc"));
dbg("LATIN SMALL LETTER U WITH DIAERESIS", QString::fromUtf8("ü"));
qDebug() << "\n3. Using QString::fromLocal8Bit(char const *)";
dbg("\\u00fc", QString::fromLocal8Bit("\u00fc"));
dbg("\\xc3\\xbc", QString::fromLocal8Bit("\xc3\xbc"));
dbg("LATIN SMALL LETTER U WITH DIAERESIS", QString::fromLocal8Bit("ü"));
}
return app.exec();
}
Output on mingw 4.4.0 on Windows XP:
system name: "pl_PL"
Without codecForCStrings (default is Latin1)
codecForCStrings: "NOT SET"
codecForLocale: "System"
1. Using QString::QString(char const *)
Input: \u00fc , Unicode codepoints: "c3 bc "
Input: \xc3\xbc , Unicode codepoints: "c3 bc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fc "
2. Using QString::fromUtf8(char const *)
Input: \u00fc , Unicode codepoints: "fc "
Input: \xc3\xbc , Unicode codepoints: "fc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fffd "
3. Using QString::fromLocal8Bit(char const *)
Input: \u00fc , Unicode codepoints: "102 13d "
Input: \xc3\xbc , Unicode codepoints: "102 13d "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fc "
With codecForCStrings set to UTF-8
codecForCStrings: "UTF-8"
codecForLocale: "System"
1. Using QString::QString(char const *)
Input: \u00fc , Unicode codepoints: "fc "
Input: \xc3\xbc , Unicode codepoints: "fc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fffd "
2. Using QString::fromUtf8(char const *)
Input: \u00fc , Unicode codepoints: "fc "
Input: \xc3\xbc , Unicode codepoints: "fc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fffd "
3. Using QString::fromLocal8Bit(char const *)
Input: \u00fc , Unicode codepoints: "102 13d "
Input: \xc3\xbc , Unicode codepoints: "102 13d "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fc "
Without codecForCStrings (default is Latin1), with codecForLocale set to UTF-8
codecForCStrings: "NOT SET"
codecForLocale: "UTF-8"
1. Using QString::QString(char const *)
Input: \u00fc , Unicode codepoints: "c3 bc "
Input: \xc3\xbc , Unicode codepoints: "c3 bc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fc "
2. Using QString::fromUtf8(char const *)
Input: \u00fc , Unicode codepoints: "fc "
Input: \xc3\xbc , Unicode codepoints: "fc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fffd "
3. Using QString::fromLocal8Bit(char const *)
Input: \u00fc , Unicode codepoints: "fc "
Input: \xc3\xbc , Unicode codepoints: "fc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fffd "
Without codecForCStrings (default is Latin1), with codecForLocale set to Latin1
codecForCStrings: "NOT SET"
codecForLocale: "ISO-8859-1"
1. Using QString::QString(char const *)
Input: \u00fc , Unicode codepoints: "c3 bc "
Input: \xc3\xbc , Unicode codepoints: "c3 bc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fc "
2. Using QString::fromUtf8(char const *)
Input: \u00fc , Unicode codepoints: "fc "
Input: \xc3\xbc , Unicode codepoints: "fc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fffd "
3. Using QString::fromLocal8Bit(char const *)
Input: \u00fc , Unicode codepoints: "c3 bc "
Input: \xc3\xbc , Unicode codepoints: "c3 bc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fc "
codecForCStrings: "NOT SET"
codecForLocale: "ISO-8859-1"
1. Using QString::QString(char const *)
Input: \u00fc , Unicode codepoints: "c3 bc "
Input: \xc3\xbc , Unicode codepoints: "c3 bc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fc "
2. Using QString::fromUtf8(char const *)
Input: \u00fc , Unicode codepoints: "fc "
Input: \xc3\xbc , Unicode codepoints: "fc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fffd "
3. Using QString::fromLocal8Bit(char const *)
Input: \u00fc , Unicode codepoints: "c3 bc "
Input: \xc3\xbc , Unicode codepoints: "c3 bc "
Input: LATIN SMALL LETTER U WITH DIAERESIS , Unicode codepoints: "fc "
I'd like to thank thiago, cbreak, peppe and heinz from #qt freenode.org IRC channel for showing and helping me to understand issues involved here.
这篇关于使用UTF-8或Latin1编码将QString转换为QByteArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!