zoukankan      html  css  js  c++  java
  • 做一个运行界面

    做一个运行界面

     首先拖拽ui界面,看起来基本差不太多

     

     

     

     

    当combobox中没有文字时,确定按钮无效

    编写一个槽函数

    void Widget::updatebtnstate(QString str)
    {
        //combobox的文本为空时
        if(str.isEmpty())
        {
            //surebutton变为不可选择状态
            ui->sureButton->setEnabled(false);
        }
        else if(!ui->sureButton->isEnabled())
        {
            //按钮可以按
            ui->sureButton->setEnabled(true);
        }
    }

    然后将button和combobox链接起来

       connect(ui->comboBox,SIGNAL(currentTextChanged(QString)),this,SLOT(updatebtnstate(QString)));

    再把按钮改为默认不可选择

    这样就达成了这样的状态

     

    然后再确定按钮继续添加槽函数

    void Widget::runotherapp()
    {
        qDebug()<<"运行runotherapp";
        //获取当前文本
        QString cmd = ui->comboBox->currentText();
        //在堆空间上申请一个newapp
        QProcess *newapp = new QProcess(this);
        //运行该程序
        qDebug()<<"运行程序";
        newapp->start(cmd);
        qDebug()<<"运行结束";
    }

    链接函数

        connect(ui->sureButton,SIGNAL(clicked(bool)),this,SLOT(runotherapp()));

    这样就可以再点击确定按钮后进入输入的cmd程序了

    接下来想办法让输入cmd后,键入回车也能达到同样的效果

    找一下他的信号函数

     

     改变下标函数

    当下标改变时,也执行确定按钮的功能runotherapp()

        connect(ui->comboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(runotherapp()));

    然后实现取消按钮

        connect(ui->canlButton_2,SIGNAL(clicked(bool)),this,SLOT(close()));

    cpp文件实现函数代码如下

    #include "widget.h"
    #include "ui_widget.h"
    #include <QString>
    #include <QProcess>
    #include <QDebug>
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::Widget)
    {
        ui->setupUi(this);
        connect(ui->comboBox,SIGNAL(currentTextChanged(QString)),this,SLOT(updatebtnstate(QString)));
        connect(ui->sureButton,SIGNAL(clicked(bool)),this,SLOT(runotherapp()));
        connect(ui->comboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(runotherapp()));
        connect(ui->canlButton_2,SIGNAL(clicked(bool)),this,SLOT(close()));
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    void Widget::updatebtnstate(QString str)
    {
        //combobox的文本为空时
        if(str.isEmpty())
        {
            //surebutton变为不可选择状态
            ui->sureButton->setEnabled(false);
        }
        else if(!ui->sureButton->isEnabled())
        {
            //按钮可以按
            ui->sureButton->setEnabled(true);
        }
    }
    
    void Widget::runotherapp()
    {
        qDebug()<<"运行runotherapp";
        //获取当前文本
        QString cmd = ui->comboBox->currentText();
        //在堆空间上申请一个newapp
        QProcess *newapp = new QProcess(this);
        //运行该程序
        qDebug()<<"运行程序";
        newapp->start(cmd);
        qDebug()<<"运行结束";
    }
  • 相关阅读:
    第一次冲刺04
    第一次冲刺03
    第一次冲刺02
    团队站立会议3(第二阶段)
    团队站立会议2(第二阶段)
    团队站立会议1(第二阶段)
    Alpha版总结会议
    “来用”alpha版使用说明书
    团队绩效评估计划
    第一阶段其他团队对我们的意见汇总
  • 原文地址:https://www.cnblogs.com/qifeng1024/p/12793372.html
Copyright © 2011-2022 走看看