这里是一段代码:的QThread不退出
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);
}
信号serverClosed()被emmited但ServerThread似乎不退出()。为什么?
我假设,既然你说ServerThread没有'quit()',你在调用'start()'的地方? – HostileFork 2011-06-03 19:12:45
是的。我读过它是因为 server.start(); std :: string命令; do std :: getline(std :: cin,command); server.executeCommand(command.c_str()); } while(true); 但我怎样才能创建一个输入循环而不锁定主线程? – OneMoreVladimir 2011-06-03 19:17:52
另外:你的意图是executeCommand在ServerThread的线程中运行?如果你只是把它变成一个普通的成员函数,它就会在调用者的线程中运行......你需要它在一个插槽中。 – HostileFork 2011-06-03 19:18:13