QT

发布于:2024-06-24 ⋅ 阅读:(155) ⋅ 点赞:(0)

1号文件头文件onewgt.h

#ifndef ONEWGT_H
#define ONEWGT_H

#include <QWidget>
#include <QMessageBox>
#include <QLineEdit>

QT_BEGIN_NAMESPACE
namespace Ui { class onewgt; }
QT_END_NAMESPACE

class onewgt : public QWidget
{
    Q_OBJECT

public:
    onewgt(QWidget *parent = nullptr);
    ~onewgt();
signals:
    void my_signal();
private slots:
    void on_pushButton_2_clicked();
private slots:
    void on_pushButton_clicked();
private:
    Ui::onewgt *ui;
};
#endif // ONEWGT_H

2号文件头文件twowgt.h

#ifndef TWOWGT_H
#define TWOWGT_H

#include <QWidget>

namespace Ui {
class twowgt;
}

class twowgt : public QWidget
{
    Q_OBJECT

public:
    explicit twowgt(QWidget *parent = nullptr);
    ~twowgt();
public slots:
    void my_slot();
private:
    Ui::twowgt *ui;
};

#endif // TWOWGT_H

man.cpp文件

#include "onewgt.h"
#include "twowgt.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    onewgt w;
    w.show();
    twowgt x;
    QObject::connect(&w,&onewgt::my_signal,&x,&twowgt::my_slot);
    return a.exec();
}

onewgt.cpp文件

#include "onewgt.h"
#include "ui_onewgt.h"

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

    ui->lineEdit->setPlaceholderText("Username");
    ui->lineEdit_2->setPlaceholderText("Passwd");
}

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

void onewgt::on_pushButton_2_clicked()
{
    close();
}
void onewgt::on_pushButton_clicked()
{
    QString get = ui->lineEdit->text();
    QString getpa = ui->lineEdit_2->text();
    if(get == "admin" && getpa == "123456")
    {
        close();
        emit my_signal();
    }else
    {
        QMessageBox::warning(this, "登录", "登录失败");
        ui->lineEdit->clear();
        ui->lineEdit_2->clear();
    }
}
 

twowgt.cpp文件

#include "twowgt.h"
#include "ui_twowgt.h"

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

void twowgt::my_slot()
{
    this->show();
}


网站公告

今日签到

点亮在社区的每一天
去签到