码迷,mamicode.com
首页 > 系统相关 > 详细

qt中创建进程

时间:2016-04-01 11:29:10      阅读:896      评论:0      收藏:0      [点我收藏+]

标签:

进程:
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();
}

 

qt中创建进程

标签:

原文地址:http://www.cnblogs.com/defen/p/5344273.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!