24/01/09 qt work

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

将登录按钮使用qt5版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出"登录成功",并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空

cpp 复制代码
头文件:

#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H

#include <QMainWindow>
#include <QLineEdit>
#include <QTextEdit>
#include <QDebug>

QT_BEGIN_NAMESPACE
namespace Ui { class MyMainWindow; }
QT_END_NAMESPACE

class MyMainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MyMainWindow(QWidget *parent = nullptr);
    ~MyMainWindow();

private:
    Ui::MyMainWindow *ui;

public slots:
    //登录槽函数
    void loginButton_clicked();
    //退出槽函数
    void exitButton_clicked();

};

#endif // MYMAINWINDOW_H

xxx.cpp

#include "mymainwindow.h"
#include "ui_mymainwindow.h"

MyMainWindow::MyMainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MyMainWindow)
{
    this->setWindowTitle("ui");
    ui->setupUi(this);
    ui->logoLabel->setPixmap(QPixmap(":/pictrue/dt4.gif"));
    ui->logoLabel->setScaledContents(true);

    ui->passwdEdit->setEchoMode(QLineEdit::Password);

    //连接 登录 q5连接
    connect(ui->loginButton,&QPushButton::clicked,this,&MyMainWindow::loginButton_clicked);
    //连接 退出 q4连接
    connect(ui->exitButton,SIGNAL(clicked()),this,SLOT(exitButton_clicked()));
}

MyMainWindow::~MyMainWindow()
{
    delete ui;
}


void MyMainWindow::loginButton_clicked()
{
    QString username = ui->userNameEdit->text();
    if(username == NULL){
        qDebug() << "用户名为空";
        return;
    }
    QString passwd = ui->passwdEdit->text();
    if(passwd == NULL){
        qDebug() << "密码为空";
        return;
    }
    if(username != "admin"){
        qDebug() << "用户名不正确";
        ui->userNameEdit->setText("");
        return;
    }
    if(passwd != "123456"){
        qDebug() << "密码不正确";
        ui->passwdEdit->setText("");
        return;
    }

    qDebug() << "恭喜你,登录成功";

    this->close();
}

// 自定义退出实现
void MyMainWindow::exitButton_clicked()
{
    qDebug() << "系统退出";
    this->close();
}
  1. 思维导图
相关推荐
结衣结衣.9 分钟前
python中的函数介绍
java·c语言·开发语言·前端·笔记·python·学习
茫茫人海一粒沙12 分钟前
Python 代码编写规范
开发语言·python
原野心存12 分钟前
java基础进阶知识点汇总(1)
java·开发语言
程序猿阿伟15 分钟前
《C++高效图形用户界面(GUI)开发:探索与实践》
开发语言·c++
暗恋 懒羊羊23 分钟前
Linux 生产者消费者模型
linux·开发语言·ubuntu
五味香39 分钟前
C++学习,信号处理
android·c语言·开发语言·c++·学习·算法·信号处理
梓䈑1 小时前
【C语言】自定义类型:结构体
c语言·开发语言·windows
鱼跃鹰飞1 小时前
Leecode热题100-295.数据流中的中位数
java·服务器·开发语言·前端·算法·leetcode·面试
小蜗笔记1 小时前
在Python中实现多目标优化问题(7)模拟退火算法的调用
开发语言·python·模拟退火算法