出于某种原因,newConnection
当我在调试模式下运行时,信号似乎没有发出或正确处理。
下面是一个示例,例如,当我 telnet 到此服务器时,OnNewConnection
当我在发布模式下运行程序而不是在调试模式下运行程序时会调用它。有任何想法吗?
主文件
#include "Server.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
Server s;
return a.exec();
}
服务器.h
#ifndef SERVER_H
#define SERVER_H
#include <QtNetwork/qtcpserver.h>
class Server : public QObject {
Q_OBJECT
public:
Server();
~Server();
public slots:
void OnNewConnection();
private:
QTcpServer* server;
};
#endif
服务器.cpp
#include "Server.h"
Server::Server() {
server = new QTcpServer(this);
server->listen(QHostAddress::Any, 5000);
connect(server, SIGNAL(newConnection()), this, SLOT(OnNewConnection()));
}
Server::~Server() {
}
void Server::OnNewConnection() {
exit(0); // whatever i put here, it's not called in debug mode
}