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().
精彩评论