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();
}
相关推荐
luoyayun3616 小时前
Qt + FFmpeg 视频工具:视频一键压缩功能实现
qt·ffmpeg·音视频·视频压缩
blueman88886 小时前
Qt5通过vcpkg中调用时,在debug模式下调试时总是调用release的plugins文件夹中的dll
c++·qt·cmake
jinyishu_9 小时前
C++ string使用方法
开发语言·c++
乐观勇敢坚强的老彭9 小时前
C++浮点数使用注意事项
开发语言·c++
库克克10 小时前
【C++ 】内联函数
java·开发语言·c++
盐焗鹌鹑蛋10 小时前
【C++】红黑树
c++
aaPIXa62212 小时前
C++采样引导优化SPGO——比PGO更智能的编译器决策新方案
java·c++·人工智能
Starmoon_dhw13 小时前
题解:P17078 夏日甜点
c++·学习·算法·图论
某不知名網友13 小时前
C/C++动态内存管理,智能指针及RAlI思想。
java·c语言·c++
hold?fish:palm14 小时前
从源码到可执行文件:C++程序的编译过程
开发语言·c++