qt tcp通讯,server端无法进入incomingConnection函数 5C

自己写了一个类继承QTcpServer,重写里面的incomingConnection函数,但是当有新的客户端连接的时候无法进入这个函数。
头文件
```class TcpServerManager : public QTcpServer
{
Q_OBJECT

public:
TcpServerManager(QObject parent);
~TcpServerManager();
QList<TcpSocketManager
> mSocketList;
void ReadUserInfo();
public slots:
void ServerNewConnection();
void ServerReadData();
void slotclientdisconnect(qintptr descriptor);
void sliotupdateserver(QString, int);
private:
QTcpSocket mp_TCPSocket;
QTcpServer
mp_TCPServer;
std::map mMapUserInfo;
protected:
virtual void incomingConnection(qintptr socketDescriptor);
};

cpp



TcpServerManager::TcpServerManager(QObject *parent)
: QTcpServer(parent)
{
ReadUserInfo();
mp_TCPServer = new QTcpServer();
mp_TCPSocket = new QTcpSocket();
if (!mp_TCPServer->listen(QHostAddress::Any, 9988))
{
QMessageBox::warning(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("服务器端监听失败!"), QMessageBox::Yes);
return;
}
//connect(mp_TCPServer, SIGNAL(newConnection()), this, SLOT(ServerNewConnection()));
}

TcpServerManager::~TcpServerManager()
{

}

void TcpServerManager::incomingConnection(qintptr socketDescriptor)
{
TcpSocketManager *tcpclientsocket = new TcpSocketManager(this);
tcpclientsocket->setSocketDescriptor(socketDescriptor);
mSocketList.append(tcpclientsocket);
connect(tcpclientsocket, &TcpSocketManager::clientdisconnected, this, &TcpServerManager::slotclientdisconnect);
connect(tcpclientsocket, &TcpSocketManager::updateserver, this, &TcpServerManager::sliotupdateserver);
}


1个回答

weixin_39553924
weixin_39553924 不是这个问题,还是谢谢你
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问