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();
}
相关推荐
再睡一夏就好1 天前
【C++闯关笔记】深究继承
java·数据结构·c++·stl·学习笔记
mjhcsp1 天前
C++ char 类型深度解析:字符与字节的双重身份
开发语言·c++·char
江公望1 天前
Qt enum ApplicationAttribute枚举值浅解
linux·qt
友友马1 天前
『 QT 』信号-槽 补充: Qt信号槽断开连接与Lambda槽技巧
开发语言·数据库·qt
Source.Liu1 天前
【CMakeLists.txt】 Qt 自动化构建配置详解
qt·自动化·librecad
jikiecui1 天前
信奥崔老师:实数型: float、double
c++·算法
Source.Liu1 天前
【CMakeLists.txt】CMake 编译定义带值参数详解
c++·qt·librecad
程序猿编码1 天前
轻量级却实用:sigtrace 如何靠 ptrace 实现 Linux 信号的捕获与阻断(C/C++代码实现)
linux·c语言·c++·信号·捕获·ptrace
曦樂~1 天前
【Qt】TCP连接--客户端和服务器
服务器·网络·c++·qt·tcp/ip
WoodWall1 天前
WebServer 02 Reactor模式
c++·后端