// регистрация типаqRegisterMetaType<QAbstractSocket::SocketState>("QAbstractSocket::SocketState");// изменение состояние сокета.connect(&m_Socket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this,SLOT(slot_OnSocketChangeState(QAbstractSocket::SocketState)));.........//------------------------------------------------------------// изменение состояние сокета. [слот]//------------------------------------------------------------void CMyClass::slot_OnSocketChangeState(QAbstractSocket::SocketState state){ switch (state) { case (QAbstractSocket::UnconnectedState): case (QAbstractSocket::ClosingState): { // пошлем наш сигнал emit Mysignal(socketID); break; } }}
void cserver::newconn(){ QTcpSocket *Client = cServ->nextPendingConnection(); connect(Client,SIGNAL(readyRead()),SLOT(readMess())); connect(Client,SIGNAL(disconnected()),this,SLOT(disconn()));
void cserver::disconn(){ QTcpSocket *Client = (QTcpSocket*) sender(); int i,j,SID=Client->socketDescriptor(); /*.....*/ int _sid = sockets.indexOf(Client); //то самое удаление sockets.remove(_sid); // из QVector /*...*/ delete Client;}
C++ (Qt)void cserver::disconn(){ QTcpSocket *Client = qobject_cast<QTcpSocket*>( sender() ); if( !Client ) return; int i,j,SID=Client->socketDescriptor(); /*.....*/ int _sid = sockets.indexOf(Client); //то самое удаление sockets.remove(_sid); // из QVector /*...*/ Client->deleteLater();}
C++ (Qt)void cserver::disconn(){ QTcpSocket *Client = qobject_cast<QTcpSocket*>( sender() ); if( !Client ) return;}
C++ (Qt)void cserver::disconn(){ ... Client->deleteLater();}
C++ (Qt)void cserver::exiting( QAbstractSocket::SocketState state ){ switch( state ){ case ( QAbstractSocket::ClosingState ):{ QTcpSocket *Client = ( QTcpSocket* ) sender(); emit hasGone( Client->socketDescroptor() ); break; } }}
C++ (Qt)QTcpSocket *Client = ( QTcpSocket* ) sender();
C++ (Qt)if( Client ){ int id=Client->socketDescroptor();}else{}