各位达达:
在下做了一个小聊天工具, 建立了一个QTcpSocket连接(是不是有点有点大材小用了, 貌似单位的电脑之间不能进行QUdpSocket通讯, 所以...), 从QTextEdit中获取字符串, 然后通过QTcpSocket发送出去. 当对方收到后, 显示到QTextEdit上的却是乱码. 请问怎么解决??? 相关代码如下:
///// Client Send To Server ///////
QString sendString = sendTxt->toPlainText(); // get text from QTextEdit "sendTxt"
QByteArray sendByteArray;
sendByteArray.append(sendString);
tcpSocket->write(sendByteArray);
///// Server receive from Client ///////
QByteArray tempByteArray = tcpSocket->readAll();
char * tempChar = tempByteArray.data();
QString tempString = tr(tempChar);
contextTxt->append(tempString ); // refresh QTextEdit "contextTxt"
注: 已经在两端的main()函数中, 添加了QTextCodec::setCodec(...). 还是不行.
实在不知道该如何讲中文转换过来. 请指教!!!