当前位置:网站首页>QT calling external program
QT calling external program
2022-04-23 13:33:00 【Micro cold】
QT Practical course :
List of articles
Source code address : QT Call the external program
Call system instructions
For similar replication 、 Mobile and other functions , Obviously, the operating system provides more complete instructions .QT
Provides QProcess
class , Used to call system instructions , It's like C In language system
equally .
for example , stay Windows
Copy commands are also provided in copy
, Then drag a button , Renamed as btnCopyFile
, Then go to slot , add to click
action
void MainWindow::on_btnCopyFile_clicked()
{
QString oldName = QFileDialog::getOpenFileName(this," Please select a file ");
QString newName = QFileDialog::getSaveFileName(this," Please enter filename ");
QProcess cpPro(this);
QString code = "copy";
ui->txtContent->setText(code);
QStringList para;
para << oldName << newName;
foreach(QString item, para)
ui->txtContent->append(item);
cpPro.start(code, para);
}
among ,cpPro
It's just one. QProcess, Used in the final call cpPro.start(code,para)
, among code
It's an instruction ready to execute , The format is QString
;para
It's a list of instructions , The type is QStringList
, That is to say QList<QString>
.
The effect is
The return value of the system instruction
QProcess
The power of , It can not only execute the command line instructions of the system , It can also capture the return value of the command line . With ls
Command as an example ( Of course ,Windows There is no self ls Of , You can use dir)
The effect is
The code is
void MainWindow::on_btnListFiles_clicked()
{
QString folder = QFileDialog::getExistingDirectory(this," Please select a folder ");
ui->lineTitle->setText(folder);
QProcess cmd;
cmd.start("dir",QStringList()<<folder);
cmd.waitForStarted();
cmd.waitForFinished();
ui->txtContent->append(cmd.readAllStandardOutput());
}
Compared to the previous code , Two more wait
, One read
, seeing the name of a thing one thinks of its function , The former is used to wait for the command to start and complete , The latter is used to get the standard output of the command line .
This involves QProcess Life cycle of :
waitForStarted()
: Blocking , Until the external program startswaitForReadyRead()
: Blocking , Until the new data in the output channel is readablewaitForBytesWritten()
: Blocking , Until the data in the input channel is writtenwaitForFinished()
: Blocking , Until the end of the external program
版权声明
本文为[Micro cold]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231324476362.html
边栏推荐
- C语言之字符串与字符数组的区别
- You and the 42W bonus pool are one short of the "Changsha bank Cup" Tencent yunqi innovation competition!
- Nodejs + websocket cycle small case
- [official announcement] Changsha software talent training base was established!
- 2020年最新字节跳动Android开发者常见面试题及详细解析
- Plato farm, a top-level metauniverse game, has made frequent positive moves recently
- CSDN高校俱乐部“名师高校行”——湖南师范大学站
- Uninstall MySQL database
- On the bug of JS regular test method
- 叮~ 你的奖学金已到账!C认证企业奖学金名单出炉
猜你喜欢
[point cloud series] multi view neural human rendering (NHR)
web三大组件之Servlet
Data warehouse - what is OLAP
[official announcement] Changsha software talent training base was established!
Common interview questions and detailed analysis of the latest Android developers in 2020
Isparta is a tool that generates webp, GIF and apng from PNG and supports the transformation of webp, GIF and apng
为什么从事云原生开发需要学习容器技术
Imx6ull QEMU bare metal tutorial 2: usdhc SD card
Vscode tips
浅谈js正则之test方法bug篇
随机推荐
[point cloud series] so net: self organizing network for point cloud analysis
Servlet of three web components
【快排】215. 数组中的第K个最大元素
爱可可AI前沿推介 (4.23)
[notes de marche]
Part 3: docker installing MySQL container (custom port)
LeetCode_DFS_中等_695.岛屿的最大面积
Nodejs + Mysql realize simple registration function (small demo)
Launcher hides app icons that do not need to be displayed
Solve the problem that Oracle needs to set IP every time in the virtual machine
POM of SSM integration xml
[point cloud series] pointfilter: point cloud filtering via encoder decoder modeling
Machine learning -- naive Bayes
These vscode extensions are my favorite
顶级元宇宙游戏Plato Farm,近期动作不断利好频频
Processbuilder tool class
On the bug of JS regular test method
Super 40W bonus pool waiting for you to fight! The second "Changsha bank Cup" Tencent yunqi innovation competition is hot!
C语言之字符串与字符数组的区别
[wechat applet] flex layout usage record