Qt-关闭进程4种方法
相关资料:
https://download.csdn.net/download/zhujianqiangqq/53195067 代码包下载
mainwindow.h
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #ifndef MAINWINDOW_H 2 #define MAINWINDOW_H 3 4 #include <QMainWindow> 5 6 #include <QCoreApplication> 7 #include <QDebug> 8 9 QT_BEGIN_NAMESPACE 10 namespace Ui { class MainWindow; } 11 QT_END_NAMESPACE 12 13 class MainWindow : public QMainWindow 14 { 15 Q_OBJECT 16 17 public: 18 MainWindow(QWidget *parent = nullptr); 19 ~MainWindow(); 20 21 private slots: 22 void on_pushButton_clicked(); 23 24 void on_pushButton_2_clicked(); 25 26 void on_pushButton_3_clicked(); 27 28 void on_pushButton_4_clicked(); 29 30 private: 31 Ui::MainWindow *ui; 32 }; 33 #endif // MAINWINDOW_H
mainwindow.cpp
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include "mainwindow.h" 2 #include "ui_mainwindow.h" 3 4 MainWindow::MainWindow(QWidget *parent) 5 : QMainWindow(parent) 6 , ui(new Ui::MainWindow) 7 { 8 ui->setupUi(this); 9 10 setWindowTitle(QStringLiteral("关闭进程4种方法")); 11 } 12 13 MainWindow::~MainWindow() 14 { 15 delete ui; 16 } 17 18 19 void MainWindow::on_pushButton_clicked() 20 { 21 qDebug() << "ThreadProcess::exit_exe:current_pid = " << QCoreApplication::applicationPid(); 22 std::string exit_cmd = "taskkill /f /PID " + std::to_string(QCoreApplication::applicationPid()); 23 system(exit_cmd.c_str()); 24 } 25 26 void MainWindow::on_pushButton_2_clicked() 27 { 28 exit(0); 29 } 30 31 void MainWindow::on_pushButton_3_clicked() 32 { 33 close(); 34 } 35 36 void MainWindow::on_pushButton_4_clicked() 37 { 38 QCoreApplication::quit(); 39 }
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我
![](https://images.cnblogs.com/cnblogs_com/FKdelphi/1101510/o_200417075318%E5%8A%A0%E6%88%91QQ.jpg)
![](https://images.cnblogs.com/cnblogs_com/FKdelphi/1101510/o_200417080925%E5%8A%A0%E6%88%91%E5%BE%AE%E4%BF%A1.jpg)