//mainwindow.cpp文件,主界面实现
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qdebug.h>
#include <qprocess.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow){
ui->setupUi(this);
}
MainWindow::~MainWindow(){
delete ui;
}
void MainWindow::on_btnPing_clicked(){
qDebug()<<QStringLiteral("开始点击");
ui->textBrowser->clear();
ui->textBrowser->setText(QStringLiteral("请等待"));
ui->textBrowser->update();
QProcess myProcess(this);
QString program = "C:/Windows/System32/cmd.exe";
QStringList arguments;
arguments <<"/c" <<"ping www.baidu.com";
myProcess.start(program,arguments);
while (myProcess.waitForFinished(100) == false) {
QByteArray qByteRead = myProcess.readAllStandardOutput();
if (!qByteRead.isEmpty()) {
ui->textBrowser->append(QString::fromLocal8Bit(qByteRead));
repaint();
}
}
QByteArray qByteRead = myProcess.readAllStandardOutput();
ui->textBrowser->append(QString::fromLocal8Bit(qByteRead));
qDebug()<<QString::fromLocal8Bit(qByteRead);
qDebug()<<"结束点击";
}