QT day2 2.21

1.使用手动连接,将登录框中的取消按钮使用qt4版本的连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数

代码:

复制代码
#include "mywidget.h"
#include "ui_mywidget.h"

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MyWidget)
{
    ui->setupUi(this);
    Btn2 = new QPushButton("取消",this);
    Btn2->resize(ui->Btn1->width(),ui->Btn1->height());
    Btn2->move(ui->Btn1->x(),ui->Btn1->y()+ui->Btn1->height()+20);
    connect(Btn2,SIGNAL(clicked()),this,SLOT(close()));
}

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

运行结果:

按下取消后窗口关闭

2.将登录按钮使用qt5版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出"登录成功",并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空

代码:

复制代码
#include "mywidget.h"
#include "ui_mywidget.h"

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MyWidget)
{
    ui->setupUi(this);
    Btn2 = new QPushButton("取消",this);
    Btn2->resize(ui->Btn1->width(),ui->Btn1->height());
    Btn2->move(ui->Btn1->x(),ui->Btn1->y()+ui->Btn1->height()+20);
    //按下取消按钮则窗口关闭
    connect(Btn2,SIGNAL(clicked()),this,SLOT(close()));

    //按下登陆按钮时,判断账号密码
    connect(ui->Btn1, &QPushButton::clicked, this, &MyWidget::my_slot);

    ui->edit2->setEchoMode(QLineEdit::Password);
    connect(ui->Btn3,SIGNAL(clicked()),this,SLOT(close()));
    //connect(ui->Btn1,&QPushButton::clicked,ui->Btn3,&QPushButton::clicked);
}

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

void MyWidget::my_slot()
{
    if((ui->edit1->text()=="admin")&&(ui->edit2->text()=="123456"))
    {
        ui->Btn1->setText("登陆成功");

        qDebug() << "登陆成功" ;
        this->close();
//        connect(ui->Btn1,SIGNAL(clicked()),this,SLOT(close()));
    }
    else
    {
        ui->Btn1->setText("登陆失败");
        ui->edit2->setText("");
    }
}


void MyWidget::on_Btn1_clicked()
{

}

运行结果:

相关推荐
郝学胜-神的一滴36 分钟前
游戏设计、原型与开发 26:四种循环
开发语言·数据结构·游戏·游戏引擎·游戏策划
泡海椒1 小时前
Java PDF 报表开发:一页简历的两种版式风格对比与折行避坑
java·开发语言·pdf
2601_962885722 小时前
如何用 Python 计算终极振荡器(Ultimate Oscillator, UOS)?
开发语言·python
benchmark_cc3 小时前
一次获取多只股票实时行情:QuantDash `quotes.get(symbols=[...])` 批量快照
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
geovindu3 小时前
python: PCA
开发语言·后端·python·算法
__万波__4 小时前
嵌入式存储技术--1.Flash物理存储
java·开发语言
Chen_harmony4 小时前
十六、ALV树
开发语言·c++
qq_274475155 小时前
第 28 篇:Promise 全解析:状态、then/catch/finally、静态方法 all/race/allSettled/any
开发语言·javascript
西西弗Sisyphus5 小时前
C++ 最小 Agentic Loop 实现 - 回调函数系列 - 初识回调(5)
开发语言·c++
程序员小杰@5 小时前
Java 统一报文转换 + 签名验签完整介绍
java·开发语言