各位大侠,帮帮忙 :
我在自定义类中定义了一个
QTcpSocket成员,然后在类的构造函数中分别关联了QTcpSocket的
connected()、
disconnected()、
error()信号到相应的槽,分别在
disconnected()和
error()关联的槽中执行了
connectToHost()命令,当我联上服务器断再断掉后为什么
disconnected()相应槽的
connectToHost()命令执行后
QTcpSocket成员能得到
connected()信号,而
error()相应槽的
connectToHost()命令执行后
QTcpSocket成员却不能得到
connected()信号呢?(附简易代码说明)
class TCP_Client : public QThread
{
Q_OBJECT
public:
.
.
.
private:
QTcpSocket m_socket;
public slots:
void ConnectSucceed();
void DestroyConnection();
};
TCP_Client::TCP_Client()
{
connect(&m_socket, SIGNAL(connected()), this, SLOT(ConnectSucceed()));
connect(&m_socket, SIGNAL(disconnected()), this, SLOT(DestroyConnection()));
// connect(&m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(DestroyConnection()));
}
.
.
.
void TCP_Client::ConnectSucceed()
{
emit CommunicationStateChanged(m_ObjectCar, TRUE);
return;
}
void TCP_Client::DestroyConnection()
{
m_socket.abort();
emit CommunicationStateChanged(m_ObjectCar, FALSE);
m_socket.connectToHost("192.168.1.1", 9998); //当第一次连接上服务器再断开后
//为什么通过disconnected()关联到该槽时,执行了这句后能进入ConnectSucceed()槽;
//而通过error()关联到该槽时,执行了这句后却不能进入ConnectSucceed()槽。似乎m_socket 跟本就没发射
connected()信号。
return;
}
[ 此帖被tercel在2009-03-28 15:54重新编辑 ]