我在写一个客户端向服务器发送字符串的程序,但是总也无法通过,相关代码如下,请高手帮忙指点一下。
服务器端:
connect(&tcpServer, SIGNAL(newConnection()),this, SLOT(acceptConnection()));
......
......
void Dialog::acceptConnection()
{
tcpServerConnection = tcpServer.nextPendingConnection();
connect(tcpServerConnection, SIGNAL(readyRead()),this, SLOT(updateServerProgress()));
}
void Dialog::updateServerProgress()
{
QDataStream in(tcpServerConnection);
in.setVersion(QDataStream::Qt_4_0);
QString nextFortune;
in >> nextFortune;
serverStatusLabel->setText(nextFortune);//这里!!!
/ *关键是这:在server上的label现示client上传过来的字符串,可是这样写没有显示,如果写成
serverStatusLabel->setText("abcd");就可以显是出来,这样的结果是不是可以理解为这个槽正常触发了,可是在服务器接收数据时写的有问题所以无法正常显示.怎样才能正常接到客户端发过来的字符串呢都郁闷好几天了,那位高手救我一把吧,跪谢了!!!!
*/
}
客户端:
connect(startButton, SIGNAL(clicked()), this, SLOT(start()));
connect(&tcpClient, SIGNAL(connected()), this, SLOT(startTransfer()));
........................
void Dialog::start()//客户机建个连接
{
tcpClient.connectToHost("192.168.102.51", 11111);
}
void Dialog::startTransfer()
{
tcpClient.write(QByteArray(10,'A'));
}
[ 此贴被XChinux在2006-10-09 13:05重新编辑 ]