QT_day2

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

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

cpp 复制代码
#include "mywidget.h"
#include "ui_mywidget.h"

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MyWidget)
{
    ui->setupUi(this);

    //窗口相关设置
    this->setWindowTitle("QQ聊天");
    this->setWindowIcon(QIcon(":/pictrue/qq.png"));
    this->setFixedSize(601,394);

    //logo设置
    ui->logoLab->setPixmap(QPixmap(":/pictrue/logo.png"));
    ui->logoLab->setScaledContents(true);

    //账号
    ui->userNameLab->resize(30,30);
    ui->userNameLab->setPixmap(QPixmap(":/pictrue/wodepeizhenshi.png"));
    ui->userNameLab->setScaledContents(true);

    ui->userNameEdit->setPlaceholderText("QQ账号/手机/邮箱");

    //密码
    ui->passwordLab->resize(30,30);
    ui->passwordLab->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
    ui->passwordLab->setScaledContents(true);

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

    //登录和取消
    ui->loginBtn->setIcon(QIcon(":/pictrue/login.png"));
    ui->cancelBtn->setIcon(QIcon(":/pictrue/cancel.png"));


    //手动连接信号和系统槽,基于qt4版本    是不友好的连接
    //取消   利用槽函数点击实现关闭
     this->connect(ui->cancelBtn,SIGNAL(clicked()),this,SLOT(cancelBtn_slots()));

     //手动连接信号和系统槽,基于qt5版本    是友好的连接
     connect(ui->loginBtn,&QPushButton::clicked,this,&MyWidget::loginBtn_slot);
}

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



void MyWidget::cancelBtn_slots()
{
    this->close();
}


void MyWidget::loginBtn_slot()
{

   if(ui->userNameEdit->text() == "admin" && ui->passwordEdit->text() == "123456")
    {
        qDebug("%s\n","登录成功");
        this->close();
    }
    else
    {
        qDebug("%s\n","登录失败");
        ui->userNameEdit->clear();
        ui->passwordEdit->clear();
    }
}

思维导图

相关推荐
Larry_Yanan3 小时前
QML学习笔记(四十三)QML与C++交互:上下文属性暴露
c++·笔记·qt·学习·ui·交互
江公望8 小时前
Qt的QT_QPA_EGLFS_INTEGRATION环境变量浅解
linux·qt·qml
精英的英9 小时前
【工具开发】适用于交叉编译环境的QT qmake项目转换vscode项目插件
人工智能·vscode·qt·开源软件
Source.Liu9 小时前
【BuildFlow & 筑流】品牌命名与项目定位说明
c++·qt·rust·markdown·librecad
unicrom_深圳市由你创科技10 小时前
工业上位机,用Python+Qt还是C#+WPF?
python·qt·c#
Larry_Yanan19 小时前
QML学习笔记(四十二)QML的MessageDialog
c++·笔记·qt·学习·ui
Main. 241 天前
从0到1学习Qt -- 创建项目
qt
共享家95271 天前
QT-常用控件(多元素控件)
开发语言·前端·qt
寻找华年的锦瑟1 天前
Qt-键鼠事件
开发语言·qt
jjjxxxhhh1231 天前
【项目-】Qt + QCustomPlot 实现频谱监测仪:四图联动、高频信号注入、鼠标交互全解析
开发语言·qt·交互