如图
我client发送部分代码是:
void Widget::send()
{
QString ss="hello server你好,服务器!!!";
tcpSocket->write(ss.toStdString().c_str(),strlen(ss.toStdString().c_str()));
//QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
//tcpSocket->write(ss.toUtf8());
// QString ss="hello server - 你好,服务器!!!";
// QByteArray dateSend = ss.toLocal8Bit();
// tcpSocket->write(dateSend);
}
server端接收:
void Widget::dataReceived()
{
while(m_pSocket->bytesAvailable())
{
QByteArray vTemp;
//vTemp = vTemp.to
vTemp = m_pSocket->readAll();
// QTextCodec *codeTransfor = QTextCodec::codecForName("GBK");
// QString vTempStr = codeTransfor->toUnicode(vTemp);//.mid(2));
QString vTempStr = QTextCodec::codecForName("GBK")->toUnicode(vTemp);
QString vFinalStr = QTextCodec::codecForName("UTF-8")->fromUnicode(vTempStr);
// QString vTempStr = QString::fromLocal8Bit(vTemp);
//QString vTempStr(vTemp);
//QString vTempStr = tr(vTemp.data());
m_pEdt_Info->append(vFinalStr);
}
}