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

}

运行结果:

相关推荐
L_autinue_Star15 分钟前
手写vector容器:C++模板实战指南(从0到1掌握泛型编程)
java·c语言·开发语言·c++·学习·stl
元气小嘉36 分钟前
前端技术小结
开发语言·前端·javascript·vue.js·人工智能
励志的大鹰哥1 小时前
V少JS基础班之第七弹
开发语言·javascript·ecmascript
AI360labs_atyun1 小时前
Java在AI时代的演进与应用:一个务实的视角
java·开发语言·人工智能·科技·学习·ai
凤年徐2 小时前
【数据结构与算法】203.移除链表元素(LeetCode)图文详解
c语言·开发语言·数据结构·算法·leetcode·链表·刷题
nbsaas-boot2 小时前
多租户架构下的多线程处理实践指南
java·开发语言·spring
无小道3 小时前
c++--typedef和#define的用法及区别
c语言·开发语言·汇编·c++
SoniaChen333 小时前
Rust基础-part2-变量和可变类型
开发语言·后端·rust
沙振宇4 小时前
【Qt 学习之路】Qt Android开发环境搭建:Ubuntu的Vmware虚拟机中的踩坑实录
android·qt·学习
鸥梨菌Honevid4 小时前
QT解析文本框数据——概述
数据库·qt·mysql