在调试模式下永远不会收到QTcpServer newConnection信号

时间:2013-11-24 12:33:59

标签: c++ qt qtnetwork qtcpserver

由于某些原因,当我在调试模式下运行时,似乎没有正确发出或处理newConnection信号。

下面是一个例子,当我例如telnet到这个服务器时,当我在发布模式下运行程序而不是调试模式时调用OnNewConnection。有什么想法吗?

的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
}

0 个答案:

没有答案