#include "application.h" #include #include #include #include ApplicationLaunch::ApplicationLaunch(QObject *parent) : QObject(parent), m_process(new QProcess(this)) { connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(finished(int, QProcess::ExitStatus))); connect(m_process, SIGNAL(started()), SLOT(process_started())); connect(m_process, SIGNAL(errorOccurred(QProcess::ProcessError)), SLOT(process_error(QProcess::ProcessError))); } QString ApplicationLaunch::appName() const { return m_AppName; } void ApplicationLaunch::setAppName(const QString &appName) { m_AppName = appName; } QString ApplicationLaunch::outFName() const { return m_outFName; } void ApplicationLaunch::setoutFName(const QString &outFName) { m_outFName = outFName; } QString ApplicationLaunch::stdERR() const { return m_stdERR; } void ApplicationLaunch::setstdERR(const QString &stdERR) { m_stdERR = stdERR; } QString ApplicationLaunch::stdOUT() const { return m_stdOUT; } void ApplicationLaunch::setstdOUT(const QString &stdOUT) { m_stdOUT = stdOUT; } int ApplicationLaunch::exitCode() { return m_exitCode; } int ApplicationLaunch::exitStatus() { return m_exitStatus; } int ApplicationLaunch::exitError() { return m_error; } QString ApplicationLaunch::arguments() const { return m_Arguments; } void ApplicationLaunch::setArguments(const QString &arguments) { m_Arguments = arguments; } void ApplicationLaunch::launchScript() { m_stdERR.clear(); m_stdOUT.clear(); m_exitCode = -1; m_exitStatus = -1; m_error = -1; m_process->start(m_AppName + " " + m_Arguments); qDebug() << "launching application ::" << m_AppName ; qDebug() << "with the Argument of"; qDebug() << m_Arguments ; } void ApplicationLaunch::finished(int exitCode, QProcess::ExitStatus status) { m_stdOUT = QString(m_process->readAllStandardOutput()); m_stdERR = QString(m_process->readAllStandardError()); m_exitCode = exitCode; m_exitStatus = status; if(m_outFName.length() > 0) { QFile outfile(m_outFName); if(outfile.open(QIODevice::ReadWrite|QFile::Truncate)){ QTextStream stream (&outfile); stream << m_stdOUT; outfile.close(); } } emit this->appFinished(); } void ApplicationLaunch::process_started(void) { emit this->appStarted(); } void ApplicationLaunch::process_error(QProcess::ProcessError app_error) { m_error = app_error; emit this->appError(); }