Qt day3
success.h
#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
#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
#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
#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
#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("");
}
}
原文地址:https://blog.csdn.net/qq_45938871/article/details/144795102
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!