void Widget::on_pushButton_clicked() //发送广播
{
QMessageBox box;
QString text=ui->textsend->toPlainText();
if(text.length()==0)
{ box.setText(tr("请输入发送内容"));
box.exec(); }
sender->writeDatagram(text.toUtf8(),text.length(), QHostAddress::Broadcast,1573);//向IP为的机器的1573端口发送数据
}
void Widget::processPendingDatagram() //处理等待的数据报
{ while(receiver->hasPendingDatagrams()) //拥有等待的数据报
{
QByteArray datagram; //拥于存放接收的数据报
datagram.resize(receiver->pendingDatagramSize());
receiver->readDatagram(datagram.data(),datagram.size()); //接收数据报,将其存放到datagram中
ui->textBrowser->setText(datagram);
//将数据报内容显示出来
}
}
请问上面代码怎么修改一下,可以让得到的数据显示中文呢