当前位置:网站首页>QT one process runs another
QT one process runs another
2022-04-23 12:15:00 【MechMaster】
Qt Interprocess communication
1. One process runs another process
- Qt Of QProcess Class is used to start and communicate with an external program .
- Use start() Function to run a process , after QProcess Get into Starting state ;
- When the program has run ,QProcess Will enter Running Status and send started() The signal ;
- When the process exits ,QProcess Return to NoRunning Status and launch finished() The signal .
2. Routine code
- mainwindow.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 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 <QDebug>
#include <QTextCodec>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Add signal and slot Association
connect(&myProcess,&QProcess::readyRead,this,&MainWindow::showResult);
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()
{
// Start Notepad program , Because it's in Windows Under the system directory , The directory has been added to the system PATH In the environment variables , So you don't need to write a specific path
//myProcess.start("notepad.exe");
QString program = "cmd.exe";
QStringList arguments;
arguments<<"/c dir&pause";
myProcess.start(program,arguments);
}
void MainWindow::showResult()
{
QTextCodec * codec = QTextCodec::codecForLocale();
qDebug()<<"showResult: "<<endl<<codec->toUnicode(myProcess.readAll());
}
void MainWindow::showState(QProcess::ProcessState state)
{
qDebug()<<"showState: ";
if(state == QProcess::NotRunning)
{
qDebug()<<"No Running";
}
else if(state == QProcess::Starting)
{
qDebug()<<"Starting";
}
else
{
qDebug()<<"Running";
}
}
void MainWindow::showError()
{
qDebug()<<"showError:"<<endl<<myProcess.errorString();
}
void MainWindow::showFinished(int exitcode, QProcess::ExitStatus exitStatue)
{
qDebug()<<"showFinished:"<<endl<<exitcode<<exitStatue;
}
版权声明
本文为[MechMaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231210423784.html
边栏推荐
- IM 体系结构:CPU架构:SIMD向量处理(IM-2.3)
- C# F23. Stringsimilarity Library: String repeatability, text similarity, anti plagiarism
- Idea code quality specification plug-in sonarlint
- Array---
- Fastjson 2 来了,性能继续提升,还能再战十年
- 电脑系统卡如何解决?
- IDEA设置版权信息
- Chapter 4 specifies the attribute of the inmemory column on the no inmemory table for im enabled filling objects: examples (Part IV of im-4.4)
- The maximum number of remote desktop servers has been exceeded
- How to switch PHP version in Windows 2008 system
猜你喜欢
Sigmoid function of activation function
Worder font page font comparison table
C# F23.StringSimilarity库 字符串重复度、文本相似度、防抄袭
Force buckle - 1137 Nth teponacci number
万事有你 未来可期 | ONES 2022校园招聘正式开启
After a circle, I sorted out this set of interview questions..
On lambda powertools typescript
亿级流量架构,服务器如何扩容?写得太好了!
Step function of activation function
一个平面设计师的异想世界|ONES 人物
随机推荐
Master slave replication configuration of MySQL
Fabric 1.0源代码分析(33) Peer #peer channel命令及子命令实现
Siri gave the most embarrassing social death moment of the year
科创人·派拉软件CEO谭翔:零信任本质是数字安全,To B也要深研用户心智
第四章 为物化视图启用和禁用IM列存储(IM 4.6)
C# F23. Stringsimilarity Library: String repeatability, text similarity, anti plagiarism
5-minute NLP: text to text transfer transformer (T5) unified text to text task model
User interface and im expression (IM 5.6)
万事有你 未来可期 | ONES 2022校园招聘正式开启
《通用数据保护条例》(GDPR)系列解读三:欧洲子公司如何向国内母公司回传数据?
第二十五课 类的静态成员变量
Qt绘制文字
Idea database navigator plug-in
Fabric 1.0 source code analysis (33) implementation of peer channel command and subcommand
Intelligent multi line elastic cloud adds independent IP address. How to realize multi line function?
The fourth chapter is about enabling and disabling the im column storage of table space for im enabled filling objects (IM 4.5)
Use kettle to copy records to and get records from results
魔域来了H5游戏详细图文架设教程
SQL exercise (I)
worder字体网页字体对照表