tcpsocket发送接收中文
1、发送QString
1)、发送:
char send[1024] = {0};
strcpy_s(send, str.toStdString().c_str());
接收:
str=QString(byte);
2)、发送:
str.toUtf8()
接收:
str=QString(byte);
2、发送file
发送:
QString filePath="d://123.txt";
QFile yoyofile;
yoyofile.setFileName(filePath);
bool isok= yoyofile.open(QIODevice::Truncate|QIODevice::ReadOnly) ;
if(false == isok)
{
qDebug() << "打开文件失败" ;
}
QByteArray byte=yoyofile.read(1024*4);//发送4k
yoyofile.close();
QByteArray array=QString::fromLocal8Bit(byte).toUtf8();
int sendRe =clientSocket->write(array);
if(sendRe == -1)
{
QMessageBox::information(this, "网络通信", "发送数据失败!");
return;
}
接收:
str=QString(byte);