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 小时前
【Java_EE】单例模式、阻塞队列、线程池、定时器
java·开发语言
狐凄1 小时前
Python实例题:基于 Python 的简单聊天机器人
开发语言·python
weixin_446122462 小时前
JAVA内存区域划分
java·开发语言·redis
悦悦子a啊2 小时前
Python之--基本知识
开发语言·前端·python
QuantumStack3 小时前
【C++ 真题】P1104 生日
开发语言·c++·算法
whoarethenext3 小时前
使用 C++/OpenCV 和 MFCC 构建双重认证智能门禁系统
开发语言·c++·opencv·mfcc
代码的奴隶(艾伦·耶格尔)4 小时前
后端快捷代码
java·开发语言
Jay_5154 小时前
C++多态与虚函数详解:从入门到精通
开发语言·c++
路来了4 小时前
Python小工具之PDF合并
开发语言·windows·python
追风赶月、5 小时前
【QT】事件(鼠标、按键、定时器、窗口)
qt