QT作业2
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);
//手动连接,将登录框中的取消按钮使用qt4版本连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数
connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(my_slot()));
//将登录按钮使用qt5版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为admin,密码是否为123456
connect(ui->pushButton,&QPushButton::clicked,this,&Widget::my_slot2);
}
//槽函数的实现
void Widget::my_slot()
{
this->close();
}
//槽函数的实现2
void Widget::my_slot2()
{
QString name=this->ui->lineEdit->text();
QString pwd=this->ui->lineEdit_2->text();
if(name=="admin"&&pwd=="123456")
{
qDebug("success");
this->close();
emit my_jump();
}
else
{
qDebug("failed");
this->ui->lineEdit_2->clear();
}
}
Widget::~Widget()
{
delete ui;
}
success.cpp
#include "success.h"
#include "ui_success.h"
success::success(QWidget *parent) :
QWidget(parent),
ui(new Ui::success)
{
ui->setupUi(this);
}
success::~success()
{
delete ui;
}
//界面2槽函数的实现
void success::myslot()
{
this->show();
}
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 s;
QObject::connect(&w,&Widget::my_jump,&s,&success::myslot);
return a.exec();
}
原文地址:https://blog.csdn.net/sinat_28344841/article/details/144796799
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!