QThread没有退出

时间:2011-06-03 19:02:54

标签: multithreading qt

这是一段代码:

class ServerThread : public QThread {
    Q_OBJECT
public:
    ServerThread();
    void executeCommand(const char *command);
private:
    Server 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);
}

发出信号服务器Closed(),但ServerThread似乎没有退出()。为什么呢?

1 个答案:

答案 0 :(得分:0)

阅读以下文章,了解QThread的工作原理:Threads, Events and QObjects。正如Colin所评论的那样,至少需要start()和moveToThread()。