相关资料:
https://download.csdn.net/download/zhujianqiangqq/53195067 代码包下载
mainwindow.h
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_HView Code
mainwindow.cpp
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 }View Code