1

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
}
  • do you use shadow build? Is it a windows? I'm suspecting that you have shadow build and firewall doesn't pass communication with application in different location. Or release version is still working, and holds `5000` port. – Marek R Nov 24 '13 at 12:52
  • I turned off the firewall completely, but that didn't help. I also only had one process up at any given time. – Panzerschlacht Nov 24 '13 at 13:03
  • Put a brekapoint on QTcpServer::newConnection and check if it's ever emitted. – peppe Nov 24 '13 at 18:05
  • add check what `listen` returns. – Marek R Nov 24 '13 at 21:45
  • Can't seem to be able to set the breakpoint on `newConnection` unfortunately since it's in an external library, but `listen` returns true! – Panzerschlacht Nov 24 '13 at 21:57

0 Answers0