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()<<"运行结束";
    }
  • 相关阅读:
    协方差矩阵
    VS2010+C#+EmguCV 配置详解
    OpenCv,EmguCv及.net之间的互动(The Interaction of OpenCv, EmguCv AND .net)
    EmguCV学习 与opencv的区别和联系
    redis新手入门,摸不着头脑可以看看<二>
    java常用工具类[待补充]
    redis新手入门,摸不着头脑可以看看<一>
    用java代码发送http请求
    Date和long类型互转
    WEB-INF目录下文件复制的几种方式
  • 原文地址:https://www.cnblogs.com/qifeng1024/p/12793372.html
Copyright © 2011-2022 走看看