【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();
}
相关推荐
龚建波3 小时前
《QDebug 2026年6月》
qt
△曉風殘月〆5 小时前
如何在Linux中安装Qt开发环境
linux·运维·qt
Quz10 小时前
QML 选择控件:Switch、CheckBox 与 RadioButton
qt
向夏威夷 梦断明暄11 小时前
【GUI-Agent】阿里通义MAI-UI 代码阅读(2)--- 实现
ui
熬夜苦读学习11 小时前
Qt常用控件
服务器·开发语言·qt
夏玉林的学习之路11 小时前
Qt 项目编译错误排查与解决记录
开发语言·qt
Kim.Li1 天前
格式塔设计原则全解析:12项核心原则在 UI/UX 中的实战应用指南
ui·产品经理·ux·视觉设计·交互设计
Quz1 天前
QML 基础按钮:Button、RoundButton 与 DelayButton
qt
Quz1 天前
QML ToolTip 组件:图标、多行文本与阴影
qt
xcyxiner1 天前
DicomViewer14(读取图像按固定窗宽窗位显示)
qt