DaemonManager: add stateChanged()

This commit is contained in:
Jaquee 2016-11-26 11:54:06 +01:00
parent 760e01b50c
commit 8d19a03b68
No known key found for this signature in database
GPG key ID: 384E52B09F45DC39
2 changed files with 16 additions and 6 deletions

View file

@ -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;

View file

@ -28,6 +28,7 @@ public slots:
void printOutput();
void printError();
void closing();
void stateChanged(QProcess::ProcessState state);
private: