有求必应

导航

qt网络通讯出现中文乱码

转自:https://blog.csdn.net/i_fuqiang/article/details/21174227

发送:

 

void TcpS::btn_send()
{
     QByteArray datasend = ui->textEdit->toPlainText().toLocal8Bit();
     m_tcpsocket->write(datasend);
}

 


接收:

 

void TcpS::read_datagram()
{
    QByteArray dataread = m_tcpsocket->readAll();
    QString str = QString::fromLocal8Bit(dataread);
    ui->textBrowser->insertPlainText(str+"\n");
}

 

 

 

posted on 2019-03-12 16:10  名侦探江户川  阅读(420)  评论(0编辑  收藏  举报