全部博文(776)
分类: LINUX
2014-09-17 17:13:56
先上代码!
QTextCodec *tc =QTextCodec::codecForName("GBK");
QByteArray ba = file.readAll();
str =tc->toUnicode(ba);
一般电脑存储中文是以gbk编码,如果这样不行,
试试把gbk换成utf-8
即:
QTextCodec *tc =QTextCodec::codecForName("utf-8");
QByteArray ba = file.readAll();
str =tc->toUnicode(ba);
就可以了!
这是自己写的:
QTextCodec *tc=QTextCodec::codecForName("GBK");
QByteArray datagram;
datagram.resize(receiver->pendingDatagramSize());
receiver->readDatagram(datagram.data(),datagram.size());
item = new QListWidgetItem;
item->setText(tc->toUnicode(datagram));