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()
{

}

运行结果:

相关推荐
未若君雅裁2 分钟前
死锁产生条件与诊断:jps、jstack、VisualVM
java·开发语言
再玩一会儿看代码2 分钟前
Java抽象类和接口区别_场景理解
java·开发语言·经验分享·笔记·python
于先生吖10 分钟前
Java消息队列优化抢单逻辑,同城搬家拉货多场景业务数据库架构设计
java·开发语言·数据库架构
半个烧饼不加肉10 分钟前
JS 底层探究--执行上下文
开发语言·前端·javascript
AI玫瑰助手15 分钟前
Python函数:global与nonlocal关键字的使用
开发语言·python·信息可视化
不会C语言的男孩16 分钟前
C++ Primer 第16章:模板与泛型编程
开发语言·c++
这个DBA有点耶18 分钟前
死锁排查进阶:从日志到根因的完整分析链
java·开发语言·数据库·sql·运维开发·学习方法·dba
三无推导18 分钟前
无需扩展的 PHP 加密方案有哪些优势:基于 php.x5.chat 的实践分析
开发语言·php·web开发·数据加密·php加密·php安全·无需扩展
jingling55518 分钟前
Flutter | 商城项目鸿蒙(OpenHarmony)适配实战
android·开发语言·前端·flutter·华为·harmonyos
Luminous.19 分钟前
C语言--day25
c语言·开发语言