mercredi 24 juin 2015

Why are the command and the command should not be run? in QProcess

My source code:

widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QtGui>
#include <QProcess>
#include "QTextEdit"
#include "QTime"

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
    QStringList list;
QString standarData;
private:
    Ui::Widget *ui;
    QProcess *pProcess;
private slots:
    void updateOutputTextEdit(void);
    void processFinished(int exitCode,QProcess::ExitStatus exitStatus);

};

#endif // WIDGET_H

this widget.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    standarData = "";

    pProcess = new QProcess;
    QString a="-b";
    connect(pProcess, SIGNAL(readyReadStandardOutput()),this,SLOT(updateOutputTextEdit()));
    connect(pProcess,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(processFinished(int,QProcess::ExitStatus)));
list<<"-b";
    //list<<"-b"+QString("-d 4 -n 1");
    //pProcess->start("top",list);
pProcess->start("top",list);
}
void Widget::updateOutputTextEdit(void){
    QByteArray newData= pProcess->readAllStandardOutput();
    QString text = QString::fromLocal8Bit(newData);
    standarData.append(text);
    standarData.append('\n');
    ui->textEdit->setText(standarData);
    pProcess->kill();
    //qDebug()<<QString(pProcess->exitCode());
}
void Widget::processFinished(int exitCode, QProcess::ExitStatus exitStatus)

{

    //QProcess::NormalExit    => 정상적인 종료

    //QProcess::CrashExit      => 비정상적인 종료

    if(exitStatus == QProcess::CrashExit)

    {


        //ui->textEdit->clear();

    }

    else if(exitCode != 0) // 0이 아니면 실패

    {
ui->textEdit->clear();

pProcess->start("top",list);
    }

    else // 0이면 성공

    {
ui->textEdit->clear();
pProcess->start("top",list);
    }
} 
Widget::~Widget()
{
    delete ui;
}

list<<"-b"; <--reaction, list<<"-b"+QString("-d 4 -n 1"); <---No reaction.

Why isn't the QProcess possible in the terminal? What is the difference between the possible and impossible things? I will give thanks to those who can provide me with a solution.

Aucun commentaire:

Enregistrer un commentaire