inputText 为 QString 类型,里面是一个中文汉字
语句1:
QByteArray bytes = inputText.toLocal8Bit();
char * tempCH1 = bytes.data();
语句2:
char * tempCH2 = inputText.toLocal8Bit().data();
很奇怪,这两个程序段出来的tempCH1 和 tempCH2 的结果是不一样的,请问为什么呢?
inputText 为 QString 类型,里面是一个中文汉字
语句1:
QByteArray bytes = inputText.toLocal8Bit();
char * tempCH1 = bytes.data();
语句2:
char * tempCH2 = inputText.toLocal8Bit().data();
很奇怪,这两个程序段出来的tempCH1 和 tempCH2 的结果是不一样的,请问为什么呢?
不好意思上面评论只是猜测而已,然后并没有猜对,去看了一下帮助手册。
Returns a pointer to the data stored in the byte array. The pointer can be used to access and modify the bytes that compose the array. The data is '\0'-terminated, i.e. the number of bytes in the returned character string is size() + 1 for the '\0' terminator.
QByteArray ba("Hello world");
char *data = ba.data();
while (*data) {
cout << "[" << *data << "]" << endl;
++data;
}
inputText.toLocal8Bit().data();这句可能就意味这"xxxx".data(),
所以第二句只能返回第一个字节,