标签:
进程:
1.QProcess 进程类
QProcess *a=new QProcess();
2.启动
void QProcess::start(const QString & command, OpenMode mode = ReadWrite)
void QProcess::start(const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite);
void QProcess::start(OpenMode mode = ReadWrite)
a->start("./1");
3.读写接口
qint64 QIODevice::write(const QByteArray & byteArray);
QByteArray QIODevice::readAll()
a->write();
a->readAll();
4.信号
void QProcess::readyReadStandardOutput();
5.结束
a->kill();
process.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include<QProcess> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_pushButton_clicked(); void get_msg(); void start_signal1(); void on_pushButton_2_clicked(); private: Ui::MainWindow *ui; QProcess *p; }; #endif // MAINWINDOW_H
process.cpp #include "mainwindow.h" #include "ui_mainwindow.h" #include<QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); p = new QProcess(); connect(p,SIGNAL(readyReadStandardOutput()),this,SLOT(get_msg())); connect(p,SIGNAL(started()),this,SLOT(start_signal1())); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { p->start("ls"); } void MainWindow::get_msg() { while(p->canReadLine()) { QString tmp = p->readLine(); ui->listWidget->addItem(tmp); } } void MainWindow::start_signal1() { qDebug()<<"start"; } void MainWindow::on_pushButton_2_clicked() { delete ui->listWidget->currentItem(); // ui->listWidget->removeItemWidget(ui->listWidget->currentItem()); qDebug()<<"remove"; //ui->listWidget->clear(); }
标签:
原文地址:http://www.cnblogs.com/defen/p/5344273.html