【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();
}
相关推荐
小小龙学IT3 分钟前
Qt 模型/视图框架(Model/View)深度解析:从 MVC 演化到数据展示架构的王者
qt·架构·mvc
Quz1 小时前
QML ComboBox 完全自定义样式:背景、内容、下拉项与箭头
qt
skr爱码士2 小时前
03_第一个Qt项目:Hello World 的完整拆解
c++·qt·客户端
ryanuo72 小时前
Shadcn/ui × Qt 6/QML:一次从 Web UI 到桌面 UI 的组件化实践
c++·qt·ui·shadcn
不会代码的小猴3 小时前
6. Qt网络编程
开发语言·c++·笔记·qt·算法
不会代码的小猴14 小时前
3. 控件学习1
开发语言·c++·笔记·qt·算法
精英的英19 小时前
记一次 Qt5 Language Server 开发
开发语言·vscode·qt
平常心的技术小牛20 小时前
Qt-快速上手-QTextCursor
开发语言·qt
盛夏绽放1 天前
Proxy与Reflect详解(二):进阶篇——手写Vue3响应式系统
ui·vue3·proxy
造火箭1 天前
Android UI自动化测试可行性评估SKILL
android·功能测试·ui