[1 楼] ::incomingConnection()是服务器端被客户端连接上后自动调用的函数。如果你想用tcpSocket的话可以用如下方法:用建立服务的server调用nextPendingConnection()这个方法可以得到tcpSocket。
-------------------------------------------
可以说的再清楚些吗?
客户端:
connect(sendButton, SIGNAL(clicked()), this, SLOT(connectServer()));
。。。。。
void Client::connectServer()
{ QString a;
a = "192.168.102.51";
tcpSocketClient->abort();
tcpSocketClient->connectToHost(QHostAddress(a), 10000);
}
服务器端:
void FortuneServer::incomingConnection(int socketDescriptor)
{
FortuneThread *thread = new FortuneThread(socketDescriptor, this);
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
..................
void FortuneThread::run()
{
}
当线程调用后在run()的什么地方调用server呀,在FortuneThread::FortuneThread(int socketDescriptor, QObject *parent) : QThread(parent), socketDescriptor(socketDescriptor)(这个是线程的构造函数),它不用QTcpServer就自动的建完了socket,不用我再调用nextPendingConnection()这个了。写的再细些好吗???跪谢了!!!