1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include "MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QWidget *widget = new QWidget;
setCentralWidget(widget);
log = new QTextEdit;
log->setReadOnly(true);
cmd = new QLineEdit;
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(cmd);
layout->addWidget(log);
widget->setLayout(layout);
proc = new QProcess(this);
connect(proc,SIGNAL(readyReadStandardOutput()),this, SLOT(readyRead()));
connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(end(int, QProcess::ExitStatus)));
connect(cmd,SIGNAL(returnPressed()),this,SLOT(executer()));
}
MainWindow::~MainWindow()
{
proc->write("exit");
if(!proc->waitForFinished(3000))
{
qWarning() << "impossible de terminer le processus correctement";
proc->kill();
}
}
void MainWindow::showEvent(QShowEvent *){
QStringList args;
args << "--login";
args << "-i";
proc->setProcessChannelMode(QProcess::MergedChannels);
proc->start("C:\\cygwin\\Cygwin.bat", args);
if (proc->waitForFinished(5000)){
log->append("started !");
}
else {
log->append("too long !");
}
}
void MainWindow::readyRead()
{
while(proc->canReadLine())
{
QByteArray buffer(proc->readLine());
log->append(QString(buffer.data()));
}
}
void MainWindow::end(int exitCode, QProcess::ExitStatus exitStatus){
log->append(QString("fin, exitCode = %1 ; exitStatus = %2").arg(exitCode).arg(exitStatus));
}
void MainWindow::executer(){
proc->write((cmd->text()+"\n").toUtf8());
cmd->clear();
} |
Partager