【QT-UI】

1.使用手动连接,将登录框中的取消按钮使用qt4版本的连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数
cpp 复制代码
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
//使用qt4将右上角x设置关闭触发
    connect(btn2,SIGNAL(clicked()),this,SLOT(close_slot()));

    //使用qt5将快速登录按钮设置触发事件
    connect(btn1,&QPushButton::clicked,this,&MyWidget::log_slot);
}

void MyWidget::close_slot()
{
    this->close();
}

void MyWidget::log_slot(){
    //比较账号和密码
    if(QString::compare("admin",edt1->text())==0 && QString::compare("123456",edt2->text())==0){
        qDebug()<<"登录成功";
        this->close();
    }else {
        edt2->clear();
        qDebug()<<"登录失败";
    }
}

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

void MainWindow::on_closebtn_clicked()
{
    this->close();
}
相关推荐
Lhan.zzZ6 小时前
笔记_2026.4.28_004
c++·ide·笔记·qt
笑鸿的学习笔记16 小时前
qt-C++语法笔记之Qt Graphics View 框架中的类型辨析完全指南
c++·笔记·qt
ZC跨境爬虫19 小时前
跟着 MDN 学 HTML day_12:(HTML网页图片嵌入)
前端·javascript·css·ui·html
朗迹 - 张伟19 小时前
用AI开发QT——Qt与Trae开发环境搭建
开发语言·qt·策略模式
爱看书的小沐20 小时前
【小沐学GIS】基于C++渲染三维飞行仿真Flight Simulation(OpenGL )第十三期
c++·qt·webgl·opengl·飞行仿真·flight
辞旧 lekkk21 小时前
【Qt】初识(上)
开发语言·数据库·qt·学习·萌新
ZC跨境爬虫1 天前
跟着 MDN 学 HTML day_11:(语义化容器全站重构+独立CSS拆分+字体合规引入)
前端·css·ui·重构·html·edge浏览器
ZC跨境爬虫1 天前
跟着 MDN 学 HTML day_10:(超链接核心语法+路径规则)
前端·css·笔记·ui·html·edge浏览器
ZC跨境爬虫1 天前
跟着 MDN 学 HTML day_9:(信件语义标记)
前端·css·笔记·ui·html
小短腿的代码世界1 天前
Qt日志系统深度解析:从qDebug到企业级日志框架
开发语言·qt