For some reason, the newConnection
signal does not seem to be emitted or handled correctly when I run in debug mode.
Below is an example, when I for example telnet to this server, OnNewConnection
is called when i run the program in release mode but not in debug mode. Any ideas?
main.cpp
#include "Server.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
Server s;
return a.exec();
}
Server.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
Server.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
}