【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();
}
相关推荐
风闲12173 小时前
Qt源码编译记录
开发语言·qt
864记忆4 小时前
Qt c++的基础语法有哪些?
开发语言·c++·qt
江公望4 小时前
Qt QHostInfo::lookupHost()函数,10分钟讲清楚
开发语言·qt·qml
胡斌附体6 小时前
qt showevent引发的问题
qt·qt creator·问题排查·思路·报警·showevent·重复打印
Dneccc6 小时前
Qt5配置MSVC2017
开发语言·qt
江公望6 小时前
Qt QByteArray类型,10分钟讲清楚
开发语言·c++·qt
小灰灰搞电子6 小时前
Qt Sensors 传感器框架详解
开发语言·qt
LNN20226 小时前
Qt 5.8 中的 Qt Test:轻松实现自动化测试
开发语言·qt
MediaTea7 小时前
Photoshop 调整命令使用详解(合集 · 2026版)
ui·photoshop
菜鸟-0115 小时前
上位机---QT
开发语言·qt