QT day2

mainwindow.h

cpp 复制代码
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
signals:
    void my_signal();
public slots:
    void my_slot();//自定义一个槽函数
    void loginbtn_slot();

private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

mainwindow.cpp

cpp 复制代码
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //窗口的相关设置
    this->setWindowTitle("QQ");
    this->setWindowIcon(QIcon(":/pictrue/qq.png"));

    //标签的相关设置
    ui->logolabel->setPixmap(QPixmap(":/pictrue/logo.png"));
    ui->logolabel->setScaledContents(true);

    //账号和密码
    ui->usernamelabel->resize(35,35);
    ui->usernamelabel->setPixmap(QPixmap(":/pictrue/userName.jpg"));
    ui->usernamelabel->setScaledContents(true);

    ui->passwordlabel->resize(35,35);
    ui->passwordlabel->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
    ui->passwordlabel->setScaledContents(true);

    ui->usernamelineEdit->setPlaceholderText("QQ账号/手机号码/邮箱");
   // ui->usernamelineEdit->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
   // ui->usernamelineEdit->adjustSize();
    ui->passwordlineEdit->setEchoMode(QLineEdit::Password);

    //登录按钮和取消登录按钮
    ui->loginbtn->setIcon(QIcon(":/pictrue/login.png"));
    ui->cancelbtn->setIcon(QIcon(":/pictrue/cancel.png"));

    //手动连接信号和槽函数,基于qt4版本 是不友好的连接
    connect(ui->cancelbtn,SIGNAL(clicked()),this,SLOT(my_slot()));

    //qt5版本 判断账号是否为admin,密码是否为123456
    connect(ui->loginbtn,&QPushButton::clicked,this,&MainWindow::loginbtn_slot);


}

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

void MainWindow::my_slot()
{
    this->close();
}

void MainWindow::loginbtn_slot()
{
    if(ui->usernamelineEdit->text()=="admin" && ui->passwordlineEdit->text()=="123456")
    {
        qDebug() << "登录成功";
    }
    else
    {
        qDebug() << "登录失败";
        ui->usernamelineEdit->setText("");
        ui->passwordlineEdit->setText("");
        this->close();
    }

}
相关推荐
cpp_learners5 小时前
QT 引入Quazip和Zlib源码工程到项目中,无需编译成库,跨平台,压缩进度
qt·zlib·加密压缩·quazip
数巨小码人9 小时前
QT SQL框架及QSqlDatabase类
jvm·sql·qt
程序员老舅12 小时前
C++ Qt项目教程:WebServer网络测试工具
c++·qt·测试工具·webserver·qt项目·qt项目实战
enyp8013 小时前
Qt QStackedWidget 总结
开发语言·qt
luoyayun36113 小时前
Trae+Qt+MSVC环境配置
vscode·qt·环境配置·trae qt
水瓶丫头站住21 小时前
Qt中QDockWidget的使用方式
开发语言·qt
laimaxgg21 小时前
Qt常用控件之数字显示控件QLCDNumber
开发语言·c++·qt·qt5·qt6.3
牵牛老人1 天前
Qt开发中出现中文乱码问题深度解析与解决方案
开发语言·qt
Zfox_1 天前
【QT】信号与槽 & 窗口坐标
开发语言·c++·qt·qt5
进击ing小白1 天前
Qt程序退出相关资源释放问题
开发语言·qt