开发者

QThread doesn't exit

Here is a piece of code:

class ServerThread : public QThread {
    Q_OBJECT
public:
    ServerThread();
    void executeCommand(const char *command);
private:
    S开发者_JAVA百科erver server;
};

void Server::executeCommand(const char *command) {
    QString qCommand = command;
    if (qCommand == "close") {
        closeServer();
        emit serverClosed();
    } else if (true) {

    }
}

ServerThread::ServerThread() {
    connect(&server, SIGNAL(serverClosed()), this, SLOT(quit()));
}

void ServerThread::executeCommand(const char *command) {
    server.executeCommand(command);
}

The signal serverClosed() is emmited but ServerThread doesn't seem to quit(). Why?


Read to following article to understand the workings of QThread: Threads, Events and QObjects. As Colin has commented you will need at least start() and moveToThread().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜