#ifndef MAINWINDOW_H#define MAINWINDOW_H#include "ui_mainwindow.h"#include <QProcess>class MainWindow : public QMainWindow, private Ui::MainWindow{ Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); QProcess *myprocess;private slots: void on_pushButton_clicked(); void outExec(); void finishExec ( int exitCode, QProcess::ExitStatus exitStatus );};#endif // MAINWINDOW_H
#include "mainwindow.h"#include <QDebug>#include <QDir>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ setupUi(this);}void MainWindow::on_pushButton_clicked(){ QString programm = lineEdit->text(); myprocess = new QProcess(this); myprocess->setObjectName(programm); //myprocess->start(QString("exec\\" + programm).toAscii()); myprocess->start(QString("cmd /C " + QDir::currentPath() + "/exec/" + programm).toAscii()); qDebug() << "RUN " << QString("cmd /C " + QDir::currentPath() + "/exec/" + programm).toAscii(); connect(myprocess, SIGNAL(readyReadStandardOutput ()), this, SLOT(outExec())); connect(myprocess, SIGNAL(finished (int,QProcess::ExitStatus)), this, SLOT(finishExec(int,QProcess::ExitStatus)));}void MainWindow::outExec(){ QString out = myprocess->readAllStandardOutput(); qDebug() << "__" << out; plainTextEdit->appendPlainText(QString(out));}void MainWindow::finishExec ( int exitCode, QProcess::ExitStatus exitStatus ){ QString out = myprocess->readAllStandardOutput(); qDebug() << out; plainTextEdit->appendPlainText(QString(out));}
p->start(QString("cmd /C \"%1\"").arg(QDir::currentPath()+"/attrib.exe"));
connect(myprocess, SIGNAL(readyReadStandardError ()), this, SLOT(outExec()));И в обоих функциях QTextCodec *codec = QTextCodec::codecForName("CP866"); //Windows-1251 CP1251 KOI8-R out += codec->toUnicode(myprocess->readAllStandardError());
myprocess->setStandardOutputFile(programm + ".log",QIODevice::WriteOnly); myprocess->setObjectName(programm);
QString name = currentProcess->objectName(); QFile file; file.setFileName(name + ".log"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return; } else { QString logFile; QTextStream in(&file); while (!in.atEnd()) { logFile += in.readLine(); } if (logFile!="") textEdit->setText(logFile); else return; }