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

功能实现

思维导图

相关推荐
终极定律3 分钟前
qt:输入控件操作
开发语言·qt
FL162386312912 分钟前
[C++]使用纯opencv部署yolov12目标检测onnx模型
c++·opencv·yolo
JenKinJia18 分钟前
Windows10配置C++版本的Kafka,并进行发布和订阅测试
开发语言·c++
wen__xvn1 小时前
每日一题洛谷P1914 小书童——凯撒密码c++
数据结构·c++·算法
云中飞鸿1 小时前
MFC中CString的Format、与XML中的XML_SETTEXT格式化注意
xml·c++·mfc
小小小白的编程日记2 小时前
List的基本功能(1)
数据结构·c++·算法·stl·list
努力可抵万难3 小时前
C++11新特性
开发语言·c++
ox00803 小时前
C++ 设计模式-策略模式
c++·设计模式·策略模式
egoist20233 小时前
【C++指南】一文总结C++类和对象【上】
开发语言·c++·类和对象·内存对齐·热榜·this指针·c++ 11
月上柳梢头&3 小时前
[C++ ]使用std::string作为函数参数时的注意事项
开发语言·c++·算法