当前位置:网站首页>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
边栏推荐
- Imx6ull QEMU bare metal tutorial 2: usdhc SD card
- [official announcement] Changsha software talent training base was established!
- [point cloud series] multi view neural human rendering (NHR)
- Remove the status bar
- Common commands of ADB shell
- LeetCode_DFS_中等_695.岛屿的最大面积
- 【快排】215. 数组中的第K个最大元素
- 【动态规划】221. 最大正方形
- RTOS mainstream assessment
- Esp32 vhci architecture sets scan mode for traditional Bluetooth, so that the device can be searched
猜你喜欢
![[wechat applet] flex layout usage record](/img/ab/7b2392688d8a0130e671f179e09dce.png)
[wechat applet] flex layout usage record

【官宣】长沙软件人才实训基地成立!

顶级元宇宙游戏Plato Farm,近期动作不断利好频频

./gradlew: Permission denied

Lpddr4 notes

CMSIS cm3 source code annotation

Imx6ull QEMU bare metal tutorial 1: GPIO, iomux, I2C

Nodejs + websocket cycle small case

RTOS mainstream assessment
![[point cloud series] neural opportunity point cloud (NOPC)](/img/ba/24417762ef5c52d2d6b57f18a3b0a2.png)
[point cloud series] neural opportunity point cloud (NOPC)
随机推荐
Esp32 vhci architecture sets scan mode for traditional Bluetooth, so that the device can be searched
顶级元宇宙游戏Plato Farm,近期动作不断利好频频
这个SQL语名是什么意思
SPI NAND flash summary
playwright控制本地谷歌浏览打开,并下载文件
Explanation of input components in Chapter 16
2020年最新字节跳动Android开发者常见面试题及详细解析
[dynamic programming] 221 Largest Square
切线空间(tangent space)
LeetCode_ DFS_ Medium_ 695. Maximum area of the island
[indicators] precision, recall
XML
What do the raddr and rport in webrtc ice candidate mean?
集简云 x 飞书深诺,助力企业运营部实现自动化办公
[andorid] realize SPI communication between kernel and app through JNI
Office 2021 installation package download and activation tutorial
Cross carbon market and Web3 to achieve renewable transformation
Uninstall MySQL database
TCP 复位gongji原理和实战复现
Common analog keys of ADB shell: keycode