【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();
}
相关推荐
用户8402409736085 小时前
使用 PyQt5 打造功能完备的 PDF 编辑器:从设计到实现全解析
qt
Quz10 小时前
QML RangeSlider 组件:范围选择与双滑块样式
qt
luoyayun36111 小时前
【Qt for Harmony】 Qt 5.12.12 鸿蒙版 Windows 交叉编译
qt·harmonyos·qt for harmony
秋田君11 小时前
Qt_常用控件使用学习
数据库·qt·学习
wWYy.12 小时前
基于Raft的分布式Kv存储项目:raft.h
开发语言·分布式·qt
茯苓gao1 天前
嵌入式开发笔记:QSerialPort 完整使用指南——从基础 API 到工程实战
笔记·嵌入式硬件·qt·学习
绿浪19841 天前
WPF UI标准流水线
ui·wpf
丁劲犇1 天前
AI辅助快速实现动态多载波PSK随机信号源
人工智能·qt·ai·sdr·多相滤波·动态生成
Quz1 天前
QML Slider 组件:基础滑块、自定义手柄、刻度标记与自定义轨道
qt