123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #include "application.h"
- #include <QProcess>
- #include <QDebug>
- #include <QFile>
- #include <QTextStream>
- Application::Application(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 Application::appName() const
- {
- return m_AppName;
- }
- void Application::setAppName(const QString &appName)
- {
- m_AppName = appName;
- }
- QString Application::outFName() const
- {
- return m_outFName;
- }
- void Application::setoutFName(const QString &outFName)
- {
- m_outFName = outFName;
- }
- QString Application::stdERR() const
- {
- return m_stdERR;
- }
- void Application::setstdERR(const QString &stdERR)
- {
- m_stdERR = stdERR;
- }
- QString Application::stdOUT() const
- {
- return m_stdOUT;
- }
- void Application::setstdOUT(const QString &stdOUT)
- {
- m_stdOUT = stdOUT;
- }
- int Application::exitCode()
- {
- return m_exitCode;
- }
- int Application::exitStatus()
- {
- return m_exitStatus;
- }
- int Application::exitError()
- {
- return m_error;
- }
- QString Application::arguments() const
- {
- return m_Arguments;
- }
- void Application::setArguments(const QString &arguments)
- {
- m_Arguments = arguments;
- }
- void Application::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 << "\n with the Argument of \n" + m_Arguments ;
- }
- void Application::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 Application::process_started(void)
- {
- emit this->appStarted();
- }
- void Application::process_error(QProcess::ProcessError app_error)
- {
- m_error = app_error;
- emit this->appError();
- }
|