#include <QProcess>
//方法一:直接执行shell命令
//关机
void MainWindow::Shutdown()
{
QProcess::execute("shutdown now");
}
//方法二:简单的shell编辑器
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QProcess>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->lineEdit,SIGNAL(returnPressed()),this,SLOT(on_pushButton_clicked()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QProcess process;
process.start(ui->lineEdit->text());
process.waitForFinished();
QByteArray output = process.readAllStandardOutput();
QString str_output = output;
ui->textBrowser->setText(str_output);
qDebug()<<output;
}
工程下载链接:https://download.csdn.net/download/future_ai/10531733