我在使用 QTcpSocket 时遇到问题,它没有发出任何信号:/
void NetworkInstance::run()
{
m_pSocket = new QTcpSocket();
connect(m_pSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError()));
connect(m_pSocket, SIGNAL(hostFound()), this, SLOT(socketHostLookupDone()));
connect(m_pSocket, SIGNAL(connected()), this, SLOT(socketConnected()));
connect(m_pSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
connect(m_pSocket, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));
QSettings s;
s.beginGroup("network");
emit log(QString("Connection to: ").append(s.value("host").toString()).append(":").append(s.value("port").toString()));
m_pSocket->connectToHost(s.value("host").toString(), s.value("port").toInt());
s.endGroup();
exec();
}
这是我的代码,我没有看到任何错误,但没有发出连接的信号(hostFound、connected 等)。在服务器上,我可以看到已建立连接并发送了数据,但客户端没有任何反应。NetworkInstance 正在扩展 QThread。