开发者

QThread doesn't exit

开发者 https://www.devze.com 2023-03-10 12:23 出处:网络
Here is a piece of code: class ServerThread : public QThread { Q_OBJECT public: ServerThread(); void executeCommand(const char *command);

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

精彩评论

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