ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

【QT-UI】

2026/8/14 4:07:08 拓冰建站 浏览量
【QT-UI】

在这里插入图片描述

1.使用手动连接,将登录框中的取消按钮使用qt4版本的连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数

在这里插入图片描述

#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();
}