QT的信号与槽函数实例

承接上文
界面部分
后面的代码做了些修改
widget.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setMaximumSize(480,232);
    this->setMinimumSize(480,232);
    QObject::connect(ui->cmdlineEdit,SIGNAL(returnPressed()),this,SLOT(on_confirmbutton_clicked()));

}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_confirmbutton_clicked()
{
    QProcess *process = new QProcess;
    QString startprocess = ui->cmdlineEdit->text();
    process->start(startprocess.trimmed());
    ui->cmdlineEdit->clear();
    this->close();
}

运行效果如下
QT的信号与槽函数实例_第1张图片

你可能感兴趣的:(C++,图形界面QT)