检查 qprocess 是否已完成
Checking whether qprocess has finished
我必须检查我的过程是否完成,我需要将其转换为布尔值,因为我想你如果。
在 MainWindow.h 中,我创建了一个对象
QProcess *action;
在主窗口中.cpp
void MainWindow:: shutdown()
{
action=new QProcess(this);
action->start("shutdown -s -t 600");
//and now I want to use if
if (action has finished)
{
QMessageBox msgBox;
msgBox.setText("Your computer will shutdown in 1 minute.");
msgBox.exec();
}
您应该连接到进程的finished
信号。每当该过程完成时,都会调用您的代码。例如
// https://github.com/KubaO/stackoverflown/tree/master/questions/process-finished-msg-38232236
#include <QtWidgets>
class Window : public QWidget {
QVBoxLayout m_layout{this};
QPushButton m_button{tr("Sleep")};
QMessageBox m_box{QMessageBox::Information,
tr("Wakey-wakey"),
tr("A process is done sleeping."),
QMessageBox::Ok, this};
QProcess m_process;
public:
Window() {
m_layout.addWidget(&m_button);
m_process.setProgram("sleep");
m_process.setArguments({"5"});
connect(&m_button, &QPushButton::clicked, &m_process, [=]{ m_process.start(); });
connect(&m_process, (void(QProcess::*)(int))&QProcess::finished, [=]{ m_box.show(); });
}
};
int main(int argc, char ** argv) {
QApplication app{argc, argv};
Window window;
window.show();
return app.exec();
}
相关文章:
- C++一个线程如何正确通信其任务已完成?
- CLion、MinGW 和 SDL2:进程已完成,退出代码为 -1073741515 (0xC0000135)
- 如何延迟生成已完成的项目序列并对其进行迭代
- 从矢量中删除已完成的线程
- CLion 没有调试我的目标之一 - 立即"进程已完成,退出代码为 0"
- 是否有任何标志指示 QT 主窗口渲染已完成
- 如何检查io_service中的任务是否已完成
- 如何确定哪个线程已完成
- OpenMP 是否将已完成部分的线程重用到另一个线程?
- WinAPI.检查窗口大小调整是否已完成
- 确定QProcess是否已完成执行或正在等待用户输入(或响应)
- 如果儿童进程崩溃,则QPROCESS ::已完成
- 检查QVariantAnimation是否已完成
- 在释放静态内存之前已完成卸载DLL
- 如何使我的程序检查安装是否已完成,然后"come back to life"
- Outlook IMAP已完成电子邮件和附件下载事件
- 通知调用方线程已完成
- 已完成线程使用的可用资源
- 如何检查 QImage::save() 是否已完成写入磁盘
- 检查 qprocess 是否已完成