zoukankan      html  css  js  c++  java
  • qt中创建进程

    进程:
    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();
    }
  • 相关阅读:
    PAT:1006(换个格式输出整数想&#183;)
    PAT 1008(数组循环右移问题)
    kaliLinux 工具dmitry参数解析
    PAT 1004(成绩排名)(C++)
    PAT乙级:我要通过(1003)
    PAT乙级:写出这个数(1002)
    PAT乙级:(3n+1)猜想 (1001)
    Linux初体验
    C语言基础入门:起源
    Linux_ pipe 匿名管道 浅解
  • 原文地址:https://www.cnblogs.com/defen/p/5344273.html
Copyright © 2011-2022 走看看