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();
}
相关推荐
dllmayday2 小时前
FontForge 手工扩展 iconfont.ttf
css·qt
码农客栈3 小时前
qt QAreaLegendMarker详解
qt
黄贵根3 小时前
C++STL系列-04. list和forward_list
c++·list
羑悻的小杀马特4 小时前
CMake 全流程开发实战:从零开始掌握C++项目构建、测试到一键分发的完整解决方案
c++·cmake
T1an-14 小时前
C++版单例模式-现代化简洁写法
c++·单例模式
一拳一个呆瓜7 小时前
【MFC】对话框属性:Absolute Align(绝对对齐)
c++·mfc
爱编程的化学家8 小时前
代码随想录算法训练营第六天 - 哈希表2 || 454.四数相加II / 383.赎金信 / 15.三数之和 / 18.四数之和
数据结构·c++·算法·leetcode·双指针·哈希
CVer儿9 小时前
qt资料2025
开发语言·qt
许怀楠10 小时前
【主页介绍】
linux·c++·贪心算法·visual studio