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("");
    }
}
相关推荐
·云扬·8 分钟前
【Java源码阅读系列37】深度解读Java BufferedReader 源码
java·开发语言
liulilittle38 分钟前
C++ i386/AMD64平台汇编指令对齐长度获取实现
c语言·开发语言·汇编·c++
Thomas_YXQ1 小时前
Unity URP法线贴图实现教程
开发语言·unity·性能优化·游戏引擎·unity3d·贴图·单一职责原则
Zz_waiting.1 小时前
Javaweb - 10.4 ServletConfig 和 ServletContext
java·开发语言·前端·servlet·servletconfig·servletcontext·域对象
Touper.2 小时前
JavaSE -- 泛型详细介绍
java·开发语言·算法
sun0077002 小时前
std::forward作用
开发语言·c++·算法
Zhen (Evan) Wang2 小时前
(豆包)xgb.XGBRegressor 如何进行参数调优
开发语言·python
虾球xz3 小时前
CppCon 2018 学习:THE MOST VALUABLE VALUES
开发语言·c++·学习
阿蒙Amon3 小时前
C#扩展方法全解析:给现有类型插上翅膀的魔法
开发语言·c#
尘浮7284 小时前
60天python训练计划----day59
开发语言·python