通过QT制作一个模仿微信主界面的界面(不要求实现具体通信功能)

main.cpp

cpp 复制代码
#include "widget.h"
#include "second.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    //实例化第二个界面
    Second s;
    QObject::connect(&w, &Widget::my_jump, &s, &Second::jump_slot);

    return a.exec();
}

second.cpp

cpp 复制代码
#include "second.h"
#include "ui_second.h"

Second::Second(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Second)
{
    ui->setupUi(this);
}

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

//第二个界面自定义的槽函数的实现
void Second::jump_slot()
{
    this->show();
}

void Second::on_sendBtn_clicked()
{
    QString msg = ui->msgEdit->text();
    ui->msgWidget->addItem(msg);
}

widget.cpp

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    connect(ui->exit_btn, &QPushButton::clicked, this, &Widget::on_exit_btn_clicked);
    connect(ui->login_btn, &QPushButton::clicked, this, &Widget::on_login_btn_clicked);

}

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


void Widget::on_login_btn_clicked()
{
    if(ui->name_edit->text() == "admin" && ui->code_edit->text() == "123456"){
        QMessageBox::information(this,
                                 "提示",
                                 "登录成功",
                                 QMessageBox::Ok
                                 );
        this->close();
        emit my_jump();
    }else{
        QMessageBox msg(
                    QMessageBox::Warning,
                    "警告",
                    "账号和密码不匹配,是否重新登陆",
                    QMessageBox::Yes | QMessageBox::No,
                    this);
        int ret = msg.exec();
        if(ret == QMessageBox::Yes){  //判断警报
            this->show();
            ui->code_edit->clear();   //清除
        }else{
            this->close();   //关闭
        }
    }
}

void Widget::on_exit_btn_clicked()
{
    this->close();
}

second.ui

widget.ui

相关推荐
狂奔小菜鸡6 分钟前
Day41 | Java中的锁分类
java·后端·java ee
hooknum20 分钟前
学习记录:基于JWT简单实现登录认证功能-demo
java
程序员Terry1 小时前
同事被深拷贝坑了3小时,我教他原型模式的正确打开方式
java·设计模式
NE_STOP1 小时前
MyBatis-缓存与注解式开发
java
码路飞1 小时前
不装 OpenClaw,我用 30 行 Python 搞了个 QQ AI 机器人
java
Re_zero1 小时前
以为用了 try-with-resources 就稳了?这三个底层漏洞让TCP双向通讯直接卡死
java·后端
SimonKing2 小时前
Fiddler抓包完全指南:从安装配置到抓包,一文讲透
java·后端·程序员
磊磊落落3 小时前
如何将 Spring Statemachine 作为一个轻量级工作流引擎来使用?
java
兆子龙17 小时前
ahooks useRequest 深度解析:一个 Hook 搞定所有请求
java·javascript