Qt day3

success.h

cpp 复制代码
#ifndef SUCCESS_H
#define SUCCESS_H

#include <QWidget>

namespace Ui {
class success;
}

class success : public QWidget
{
    Q_OBJECT

public:
    explicit success(QWidget *parent = nullptr);
    ~success();
public slots:
    void my_login_slot();


private slots:
    void on_pushButton_clicked();

private:
    Ui::success *ui;
};

#endif // SUCCESS_H

widget.h

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

public slots:
    void my_cancel_slot();
    void my_cl_slot();

signals:
    void my_login_signal();
    void my_cl_signal();

private slots:
    void on_pushButton_clicked();


private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

main.cpp

cpp 复制代码
#include "widget.h"
#include "success.h"
#include <QApplication>

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


    success login;
    QObject::connect(&w,&Widget::my_login_signal,&login,&success::my_login_slot);
    return a.exec();
}

success.cpp

cpp 复制代码
#include "success.h"
#include "ui_success.h"

success::success(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::success)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
}

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

void success::my_login_slot()
{
    this->show();
}

void success::on_pushButton_clicked()
{
    this->close();
}

widget.cpp

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

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);

    connect(ui->btn2,SIGNAL(clicked()),this,SLOT(my_cancel_slot()));
}

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

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

void Widget::my_cl_slot()
{
    QLabel *lab=new QLabel("登陆失败",this);
}


void Widget::on_pushButton_clicked()
{

    if(ui->lineEdit->text()=="admin"&&ui->lineEdit_2->text()=="123456")
    {
       emit my_login_signal();
       this->close();
    }else
    {
        ui->lineEdit->setText("");
        ui->lineEdit_2->setText("");
    }
}
相关推荐
酷爱码1 小时前
如何通过python连接hive,并对里面的表进行增删改查操作
开发语言·hive·python
画个大饼1 小时前
Go语言实战:快速搭建完整的用户认证系统
开发语言·后端·golang
喵先生!3 小时前
C++中的vector和list的区别与适用场景
开发语言·c++
Thomas_YXQ3 小时前
Unity3D Lua集成技术指南
java·开发语言·驱动开发·junit·全文检索·lua·unity3d
xMathematics3 小时前
计算机图形学实践:结合Qt和OpenGL实现绘制彩色三角形
开发语言·c++·qt·计算机图形学·cmake·opengl
yuanManGan6 小时前
C++入门小馆: 深入了解STLlist
开发语言·c++
北极的企鹅886 小时前
XML内容解析成实体类
xml·java·开发语言
BillKu6 小时前
Vue3后代组件多祖先通讯设计方案
开发语言·javascript·ecmascript
Python自动化办公社区6 小时前
Python 3.14:探索新版本的魅力与革新
开发语言·python
逐光沧海6 小时前
STL常用算法——C++
开发语言·c++