QTcpSocket socket; // 连接到远程主机 socket.connectToHost("remoteHost", 1234); // 获取连接状态 QAbstractSocket::SocketState socketState = socket.state(); // 根据连接状态进行相应处理 if (socketState == QAbstractSocket::UnconnectedState) { // 未连接状态 } else if (socketState == QAbstractSocket::HostLookupState) { // 主机查找状态 } else if (socketState == QAbstractSocket::ConnectingState) { // 连接建立状态 } else if (socketState == QAbstractSocket::BoundState) { // 已绑定状态 } else if (socketState == QAbstractSocket::ListeningState) { // 监听状态 } else if (socketState == QAbstractSocket::ClosingState) { // 关闭状态 } else { // 其他未知状态 }
##
标签:状态,socketState,qtcpsocket,else,QAbstractSocket,连接,socket From: https://www.cnblogs.com/herd/p/17977420