applicationstarter.cpp 959 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "applicationstarter.h"
  2. #include <QDebug>
  3. #include <QProcess>
  4. ApplicationStarter::ApplicationStarter(QObject *parent) :
  5. QObject(parent)
  6. {
  7. s = false;
  8. process = new QProcess();
  9. connect(process, SIGNAL(stateChanged(QProcess::ProcessState)),
  10. this, SLOT(processStateChanged()));
  11. }
  12. void ApplicationStarter::processStateChanged() {
  13. if(process->state() != QProcess::NotRunning ) {
  14. s = true;
  15. }
  16. else {
  17. s = false;
  18. }
  19. startingChanged();
  20. }
  21. bool ApplicationStarter::starting() {
  22. return s;
  23. }
  24. void ApplicationStarter::start(QString app)
  25. {
  26. qDebug() << "start app:" << app;
  27. //Close previous application
  28. if(process->state() == QProcess::Running) {
  29. process->kill();
  30. process->waitForFinished();
  31. }
  32. process->start(app);
  33. //If process starts, sending signal
  34. if(process->state() == QProcess::Starting) {
  35. s = true;
  36. startingChanged();
  37. }
  38. }