由于某些原因,当我在调试模式下运行时,似乎没有正确发出或处理newConnection
信号。
下面是一个例子,当我例如telnet到这个服务器时,当我在发布模式下运行程序而不是调试模式时调用OnNewConnection
。有什么想法吗?
#include "Server.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
Server s;
return a.exec();
}
#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
#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
}