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();
}
相关推荐
feng_you_ying_li14 分钟前
C++11,{}的初始化情况与左右值及其引用
开发语言·数据结构·c++
小樱花的樱花1 小时前
打造高效记事本:UI设计到功能实现
开发语言·c++·qt·ui
丁劲犇1 小时前
QMetaObject的invokeMethod异步阻塞调用在MCPServer开发中的巧妙应用
qt·ai·agent·异步·阻塞·mcp·mcp server
零二年的冬1 小时前
epoll详解
java·linux·开发语言·c++·链表
坚持编程的菜鸟1 小时前
The Blocks Problem
数据结构·c++·算法
tankeven1 小时前
HJ171 排座椅
c++·算法
6Hzlia2 小时前
【Hot 100 刷题计划】 LeetCode 39. 组合总和 | C++ 回溯算法与 startIndex 剪枝
c++·算法·leetcode
宵时待雨2 小时前
优选算法专题1:双指针
数据结构·c++·笔记·算法·leetcode
程序员学习随笔2 小时前
深入剖析 std::optional:实现原理、性能优化与安全编程实践
c++·安全·空值
tankeven2 小时前
HJ172 小红的矩阵染色
c++·算法