In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article "Qt how to achieve a process to run another process" most people do not understand, so the editor summarized the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "Qt how to achieve a process to run another process" article it.
1. One process runs another.
The QProcess class of Qt is used to start and communicate with an external program.
Use the start () function to run a process, after which QProcess enters the Starting state
When the program is already running, QProcess enters the Running state and sends a started () signal
When the process exits, the QProcess returns to the NoRunning state and emits the finished () signal.
two。 Routine code
Mainwindow.h
# ifndef MAINWINDOW_H#define MAINWINDOW_H#include # include namespace Ui {class MainWindow;} class MainWindow: public QMainWindow {Q_OBJECTpublic: explicit MainWindow (QWidget * parent = 0); ~ MainWindow (); private slots: void on_pushButton_clicked (); void showResult (); void showState (QProcess::ProcessState state); void showError (); void showFinished (int,QProcess::ExitStatus); private: Ui::MainWindow * ui; QProcess myProcess;}; # endif / / MAINWINDOW_H
Mainwindow.cpp
# include "mainwindow.h" # include "ui_mainwindow.h" # include # include MainWindow::MainWindow (QWidget * parent): QMainWindow (parent), ui (new Ui::MainWindow) {ui- > setupUi (this); / / add connect (& myProcess,&QProcess::readyRead,this,&MainWindow::showResult) associated with signal and slot; connect (& myProcess,&QProcess::stateChanged,this,&MainWindow::showState) Connect (& myProcess,&QProcess::errorOccurred,this,&MainWindow::showError); connect (& myProcess,SIGNAL (finished (int,QProcess::ExitStatus)), this,SLOT (showFinished (int,QProcess::ExitStatus));} MainWindow::~MainWindow () {delete ui } void MainWindow::on_pushButton_clicked () {/ / starts the notepad program, since it is in the system directory of Windows, which has been added to the system PATH environment variable, there is no need to write the specific path / / myProcess.start ("notepad.exe"); QString program = "cmd.exe"; QStringList arguments; arguments
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.