【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();
}
相关推荐
精神底层18 小时前
拒绝 UI 卡死!我用 CSnakes 实时拦截 Python 训练流,在 WPF 中重构了 ScottPlot 5 高性能 AI 看板
python·ui·wpf
blueman888818 小时前
qt5-serialbus详细解析
开发语言·网络·qt
在书中成长19 小时前
HarmonyOS 小游戏《对战五子棋》开发第27篇 - 模式选择与UI布局
ui·harmonyos
不爱记笔记1 天前
GPT-5.6 Sol 真实项目实测!Bug修复、UI重构与帆船游戏复刻
人工智能·gpt·ui·chatgpt·bug·openai
杜子不疼.2 天前
【Qt初识】信号槽(三):机制意义、断开连接与 Lambda 表达式
开发语言·数据库·qt
杜子不疼.2 天前
【Qt初识】信号槽(二):自定义信号函数与槽函数
开发语言·qt
秋田君2 天前
Qt_QVariant
开发语言·qt
杜子不疼.2 天前
【Qt初识】工程起步:项目创建、代码解读与对象树
数据库·c++·qt
前端H2 天前
生成式 UI 实战:AI 如何重塑前端界面
前端·人工智能·ui
全栈开发圈2 天前
新书速览|ComfyUI工作流赋能Photoshop
ui·photoshop