The use of processes in QT

Source: Internet
Author: User

The process used in QT needs to use the header file:include<qprocess>

First, let's look at the main functions that need to be used.

(1) Definition of the process:

  // define a process parameter

(2) Initialization of the process:

// Initializing Process Objects New Qprocess ();

(3) Start process

// Start Calculator  Mprocess->start ("calc"

(4) using process to read data

 while // read all the data in the process

(5) How to use the character stitching Qstringlist

    qstringlist list;     // stitching strings, similar    to Appen list<<"ech0";    List<<ui->comboBoxArg->currenttext ();    Mprocess->start (Ui->comboboxcmd->currenttext (), list); // start the process, followed by the parameter

Head function: Process.h

1 #ifndef Process_h2 #defineProcess_h3 4#include <QMainWindow>5#include <QProcess>//header file for process in QT6 namespaceUi {7 classProcess;8 }9 Ten classProcess: PublicQmainwindow One { A Q_object -  -  Public: the     ExplicitProcess (Qwidget *parent =0); -~Process (); -Qprocess *mprocess;//define a process parameter -  + PrivateSlots: -     voidRead_data (); +     voidon_btn_cmd_clicked (); A  at Private: -Ui::P rocess *UI; - }; -  - #endif //Process_h

Source file: Process.cpp

1#include"process.h"2#include"Ui_process.h"3#include <QDebug>4#include <QStringList>5Process::P rocess (Qwidget *parent):6 Qmainwindow (parent),7UiNewUi::P rocess)8 {9UI-&GT;SETUPUI ( This);Ten     //Initializing Process Objects OneMprocess =Newqprocess (); A  -     //listening to read data signals -Connect (mprocess,signal (readyread)), This, SLOT (Read_data ())); the  -     //add a Run parameter -Ui->comboboxarg->additem ("192.168.1.246"); -Ui->comboboxarg->additem ("./"); +Ui->comboboxarg->additem ("C + +"); -  +Ui->comboboxcmd->additem ("ifconfig"); AUi->comboboxcmd->additem ("ls"); atUi->comboboxcmd->additem ("./test"); -  - } -  -process::~Process () - { in     DeleteUI; - } to  +  - voidProcess::read_data () the { *      while(Mprocess->canreadline ())//read all the data in the process $     {Panax NotoginsengQdebug () <<mprocess->readLine (); -     } the  + } A  the voidprocess::on_btn_cmd_clicked () + { - qstringlist list; $     //stitching strings, similar to Appen $list<<"Ech0"; -List<<ui->comboboxarg->Currenttext (); -  theMprocess->start (Ui->comboboxcmd->currenttext (), list);//start the process, followed by the parameter - Wuyi}

The use of processes in QT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.