当前位置:网站首页>QT actual combat case (38) -- using qpprocess class to realize the function of starting process

QT actual combat case (38) -- using qpprocess class to realize the function of starting process

2022-06-12 23:29:00 wendy_ ya

One 、 Project introduction

utilize QProcess Class implements the function of starting a process ( Take the Notepad program as an example ).

Two 、 Basic configuration of the project

Create a new one Qt Case study , Project name: “ProcessTest”, Base class selection “QWidget”, Click to select Create UI Interface check box , Complete project creation .

3、 ... and 、UI Interface design

UI The interface layout is as follows :
 Insert picture description here
Only... Is created in the interface 1 Controls , Its name and type are as follows :

Serial number name type attribute
pbn_processQPushButtontext: Start a process

Four 、 The main program realizes

4.1 widget.h The header file

The header file contains the header file , Then add a private object , Declare button click slot function :

#include<QProcess>
private:
    QProcess myProcess;
private slots:
    void on_pbn_process_clicked();

4.2 widget.cpp Source file

Define button click slot function :

void Widget::on_pbn_process_clicked()
{
    
    // Start Notepad process 
    myProcess.start("notepad.exe");
}

Here's the launch of Windows System Notepad program ( namely notepad.exe, Because it is in Windows In the system directory of , The directory has been added to the system PATH In the environment variables , So you don't need to write a specific path ).

5、 ... and 、 Effect demonstration

The complete effect is as follows :
 Insert picture description here


ok, The above is the whole content of this article , If it helps you , Remember to like it ~

原网站

版权声明
本文为[wendy_ ya]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280955536929.html