6月15号作业

使用手动连接,将登录框中的取消按钮使用第二中连接方式,右击转到槽,在该槽函数中,调用关闭函数

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

widget.h

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTextEdit>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
private slots:
    void on_canceBin_clicked();
    void my_slot();

    void on_pos2_clicked();

private:
    Ui::Widget *ui;
    QTextEdit *text1;
};
#endif // WIDGET_H

widget.cpp

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
    ,text1(new QTextEdit)
{
    ui->setupUi(this);
    ui->bel1->setPixmap(QPixmap(":/pictrue/logo.png"));//标签贴图的路劲
    ui->bel1->setScaledContents(true);//自动适应调节
    ui->bel2->setPixmap(QPixmap(":/pictrue/wodepeizhenshi.png"));//标签贴图的路劲
    ui->bel2->setScaledContents(true);//自动适应调节
    ui->bel3->setPixmap(QPixmap(":/pictrue/passwd.jpg"));//标签贴图的路劲
    ui->bel3->setScaledContents(true);//自动适应调节
    ui->idt2->setEchoMode(QLineEdit::Password);//设置密码
    connect(ui->pos1,SIGNAL(clicked()),this,SLOT(my_slot()));
   // connect(text1,SIGNAL(),this,SLOT(my_slot()));
}

Widget::~Widget()
{
    delete ui;
}
void Widget::my_slot()
{
    if(ui->idt1->text()=="123456")
    {
        if(ui->idt2->text()=="123456")
        {
            text1->setText("登录成功");
            text1->resize(80,50);
            text1->show();
            this->close();
            return;
        }
    }
    text1->setText("登录失败");
    ui->idt2->setText("");
    text1->resize(80,50);
    text1->show();
}
void Widget::on_canceBin_clicked()
{
    this->close();
}


void Widget::on_pos2_clicked()
{
     this->close();
}

功能实现

思维导图

相关推荐
优雅的潮叭12 分钟前
c++ 学习笔记之 malloc
c++·笔记·学习
苦藤新鸡2 小时前
8.最长的无重复字符的子串
c++·力扣
Wyn_2 小时前
【ZMQ/QT】Windows11 + Qt 安装配置zmq(亲测可用)
qt·zmq·windows11
꧁Q༒ོγ꧂3 小时前
C++ 入门完全指南(四)--函数与模块化编程
开发语言·c++
864记忆3 小时前
Qt创建连接注意事项
数据库·qt·nginx
汉克老师3 小时前
GESP2025年12月认证C++八级真题与解析(判断题8-10)
c++·快速排序··lcs·gesp八级·gesp8级
qq_433554544 小时前
C++ manacher(求解回文串问题)
开发语言·c++·算法
HL_风神5 小时前
设计原则之迪米特
c++·学习·设计模式
HL_风神5 小时前
设计原则之合成复用
c++·学习·设计模式
汉克老师5 小时前
GESP2025年12月认证C++八级真题与解析(单选题10-12)
c++·递归··gesp八级·gesp8级