diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp index 293c600b..3769302a 100644 --- a/src/daemon/DaemonManager.cpp +++ b/src/daemon/DaemonManager.cpp @@ -61,6 +61,9 @@ bool DaemonManager::start() m_daemon->start(process,arguments); bool started = m_daemon->waitForStarted(); + // add state changed listener + connect(m_daemon,SIGNAL(stateChanged(QProcess::ProcessState)),this,SLOT(stateChanged(QProcess::ProcessState))); + if(!started){ qDebug() << "Daemon start error: " + m_daemon->errorString(); } else { @@ -74,16 +77,22 @@ bool DaemonManager::stop() { if(initialized){ qDebug() << "stopping daemon"; - m_daemon->terminate(); - // Wait until stopped. Max 10 seconds - bool stopped = m_daemon->waitForFinished(10000); - if(stopped) emit daemonStopped(); - return stopped; + // we can't use QProcess::terminate() on windows console process + // write exit command to stdin + m_daemon->write("exit\n"); } return true; } +void DaemonManager::stateChanged(QProcess::ProcessState state) +{ + qDebug() << "STATE CHANGED: " << state; + if(state == QProcess::NotRunning) { + emit daemonStopped(); + } +} + void DaemonManager::printOutput() { QByteArray byteArray = m_daemon->readAllStandardOutput(); @@ -111,7 +120,7 @@ bool DaemonManager::running() const if(initialized){ qDebug() << m_daemon->state(); qDebug() << QProcess::NotRunning; - + // m_daemon->write("status\n"); return m_daemon->state() > QProcess::NotRunning; } return false; diff --git a/src/daemon/DaemonManager.h b/src/daemon/DaemonManager.h index 5c1234d6..1c4ae8ad 100644 --- a/src/daemon/DaemonManager.h +++ b/src/daemon/DaemonManager.h @@ -28,6 +28,7 @@ public slots: void printOutput(); void printError(); void closing(); + void stateChanged(QProcess::ProcessState state); private: