大神帮忙!Qt 客户端给服务器发送数据,该如何处理
大神帮忙!!!Qt 客户端给服务器发送数据
客户端代码:
void UI_Main::sendMessage()
{
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt46);
out$amp;<amp>
</amp>
<amp>
</amp>
<amp>
out.device()->seek(0);
out$amp;
</amp>
<amp>
tcpSocket->write(block);
ui->sendLabel->setText("send successful");
}
服务其端代码:
void UIMain::readMessage()
{
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
QDataStream in(clientConnection);
in.setVersion(QDataStream::Qt4_6);
if (blockSize==0) {
if(clientConnection->bytesAvailable() $amp;
</amp>
<amp>
in $amp;>amp;>amp;$nbsp;blockSize;
}
if(clientConnection->bytesAvailable() $amp;
</amp>
<amp>
in $amp;>amp;>amp;$nbsp;message;
ui->showLabel->setText(message);
}
为什么服务器端收不到信息?
</amp>
相关链接