【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();
}
相关推荐
实心儿儿6 分钟前
Qt — 对象树
qt
Quz13 小时前
QML Repeater 数据模型:ListModel 与 C++ QAbstractListModel
qt
Quz13 小时前
QML Repeater 基础用法:整数、JS 数组、字符串数组三种模型
qt
江湖人称菠萝包20 小时前
【Qt】《Qt 5.9 C++开发指南》笔记-Chapter3-Qt类库概述
笔记·qt·qt5
qq_3449205621 小时前
Qt事件过滤器
开发语言·c++·qt
sunriver200021 小时前
【Qt】由于找不到 Qt6Core5Compatd.dll
qt·qt6core5compatd
qq_344920561 天前
Qt 鼠标双击QLabel全屏显示图像
c++·qt
江湖人称菠萝包1 天前
【Qt】《Qt 5.9 C++开发指南》笔记-Chapter4-常用界面设计组件
笔记·qt·qt5
实心儿儿1 天前
Qt — QtCreator 创建项目
qt
Quz2 天前
QML 常见的四种导航布局
qt