2025.9.12Qtday2

cpp 复制代码
//widget.h
#include <QWidget>
#include <QIcon>
#include <QMovie>
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
signals:
    void my_jump();//第一个界面的信号
private slots:
    void on_loginBtn_clicked();
    void on_cancelBtn_clicked();

public slots:
    void jump_slot();//第一个界面的槽函数
private:
    Ui::Widget *ui;
};
#endif // WIDGET_H
cpp 复制代码
//second.h
#include <QWidget>

namespace Ui {
class Second;
}

class Second : public QWidget
{
    Q_OBJECT

public:
    explicit Second(QWidget *parent = nullptr);
    ~Second();
signals:
    void my_jump();
public slots:
    void jump_slot();//第二个界面准备的槽函数
private slots:
    void on_btn1_clicked();

private:
    Ui::Second *ui;
};

#endif // SECOND_H
cpp 复制代码
//main.cpp
#include "widget.h"
#include "second.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    //实列化第一个界面
    Widget w;
    //实列化第二个界面
    Second s;
    QObject::connect(&w,&Widget::my_jump,&s,&Second::jump_slot);
    QObject::connect(&s,&Second::my_jump,&w,&Widget::jump_slot);
    w.show();
    return a.exec();
}
cpp 复制代码
//widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //加载资源文件
    //试列化一个动图对象
    QMovie *mv=new QMovie(":/pictrue/pictrue/qq.gif");
    //将动图设置到标签中
    ui->logoLab->setMovie(mv);
    //让动图动起来
    mv->start();
    ui->logoLab->setScaledContents(true);
    this->setWindowTitle("QQ");
    this->setWindowIcon(QIcon(":/pictrue/pictrue/qq.png"));
    this->setFixedSize(500,400);
    this->setWindowFlag(Qt::FramelessWindowHint);
    ui->userNameLab->setPixmap(QPixmap(":/pictrue/pictrue/login.png"));
    ui->userNameLab->setScaledContents(true);
    ui->paswdLab->setPixmap(QPixmap(":/pictrue/pictrue/passwd.jpg"));
    ui->paswdLab->setScaledContents(true);
}

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


void Widget::on_loginBtn_clicked()
{
    if(ui->usernameEdit->text()=="admin"&&ui->passwdEdit->text()=="123456")
    {
        QMessageBox msg(
                    QMessageBox::Information,
                    "提示",
                    "登录成功",
                    QMessageBox::NoButton,
                    this//父组件
                    );
        msg.exec();
        this->close();
        emit my_jump();
    }
    else if(ui->usernameEdit->text()=="丁真"&&ui->passwdEdit->text()=="wwwww")
    {
        qDebug()<<"妈妈生的";
    }
    else
    {
        qDebug()<<"登录失败";
        ui->passwdEdit->clear();
        ui->usernameEdit->clear();
    }
}

void Widget::jump_slot()
{
    this->show();
}

void Widget::on_cancelBtn_clicked()
{
    QMessageBox msg(
                QMessageBox::Information,
                "提示",
                "你真的要退出吗?",
                QMessageBox::Yes | QMessageBox::No,
                this//父组件
                );
    int res=msg.exec();
    if(res==QMessageBox::Yes)
    {
        this->close();
    }
}
cpp 复制代码
//second.cpp
#include "second.h"
#include "ui_second.h"
#include <QMovie>
Second::Second(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Second)
{
    ui->setupUi(this);
    //加载资源文件
    //试列化一个动图对象
    QMovie *mv=new QMovie(":/pictrue/pictrue/oopp.gif");
    //将动图设置到标签中
    ui->Lab->setMovie(mv);
    //让动图动起来
    mv->start();
    ui->Lab->setScaledContents(true);
    this->setWindowTitle("元素启动");
    this->setWindowIcon(QIcon(":/pictrue/pictrue/op.png"));
    this->setWindowFlag(Qt::FramelessWindowHint);
}
Second::~Second()
{
    delete ui;
}

void Second::jump_slot()
{
    this->show();//第二个界面显示
}

void Second::on_btn1_clicked()
{
    this->close();
    emit my_jump();
}
相关推荐
Q741_14716 分钟前
C++ 高精度计算的讲解 模拟 力扣67.二进制求和 题解 每日一题
c++·算法·leetcode·高精度·模拟
水木姚姚23 分钟前
C++ begin
开发语言·c++·算法
꧁坚持很酷꧂29 分钟前
Ubuntu系统下Qt程序连接串口设备没有问题,但运行时出现Permission denied的解决方法
linux·qt·ubuntu
老王熬夜敲代码1 小时前
泛型编程的差异抽象思想
开发语言·c++·笔记
hetao17338371 小时前
2025-12-02~03 hetao1733837的刷题记录
c++·算法
“愿你如星辰如月”2 小时前
C++11核心特性全解析
开发语言·c++
广都--编程每日问2 小时前
c++右键菜单统一转化文件为utf8编码
c++·windows·python
点云SLAM2 小时前
C++包装器之类型擦除(Type Erasure)包装器之小对象优化(SBO, Small Buffer Optimization)示例(5)
c++·内存管理·c++高级应用·c++包装器·类型擦除包装器·内存小对象优化
curry____3032 小时前
study in PTA(高精度算法与预处理)(2025.12.3)
数据结构·c++·算法·高精度算法
开始了码2 小时前
qt配置文件::INI介绍
qt