QT 做一个登录,注册的跳转页面

思路:

1.登录需要判断账号与密码是否想等,相等才可跳转新页面,匹配失败输入框提示”账号密码不匹配”。

 2.注册不需要判断,直接跳转新页面即可。

widget.cpp文件

#include "widget.h"
#include "ui_widget.h"
#include 
#include 
#include 
#include "login.h"
#include "zhuce.h"
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowTitle("千峰");
//    connect(btn,QPushButton::clicked,this,QWidget::login);
    connect(ui->btn1,SIGNAL(clicked(bool)),this,SLOT(logins()));
    connect(ui->btn2,SIGNAL(clicked(bool)),this,SLOT(registers()));

    connect(ui->lab1,SIGNAL(textChanged(QString)),this,SLOT(mesg()));
    connect(ui->lab2,SIGNAL(textChanged(QString)),this,SLOT(mesg()));

}

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

void Widget::logins()
{
    QString user = ui->lab1->text();
    QString pass = ui->lab2->text();
   if(user == "admin" && pass == "027027")
   {
       qDebug() << "登录成功" << endl;
       login* log = new login;
       log->show();
       this->close();
   }
   else
   {
       ui->lab1->setText("账号密码不匹配");
       qDebug() << endl << "账号密码不匹配" << endl;
   }

}

void Widget::mesg(){
    qDebug() << "你好" << endl;
}

void Widget::registers()
{
    zhuce* reg = new zhuce;
    reg->show();
    this->close();
}

widget.h文件

#ifndef WIDGET_H
#define WIDGET_H

#include "login.h"

#include 

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

private:
    Ui::Widget *ui;
public slots:
    void logins();
    void mesg();
    void registers();
};

#endif // WIDGET_H

login.cpp文件

#include "login.h"
#include "ui_login.h"
#include 
#include 
login::login(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::login)
{
    ui->setupUi(this);
    QLabel *label = new QLabel(this);
}

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

login.h文件

#ifndef LOGIN_H
#define LOGIN_H

#include 

namespace Ui {
class login;
}

class login : public QWidget
{
    Q_OBJECT

public:
    explicit login(QWidget *parent = 0);
    ~login();

private:
    Ui::login *ui;
};

#endif // LOGIN_H

zhuce.cpp

#include "zhuce.h"
#include "ui_zhuce.h"
#include 
#include 
zhuce::zhuce(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::zhuce)
{
    ui->setupUi(this);
    QLabel *label = new QLabel(this);
}

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

zhuce.h文件

#ifndef ZHUCE_H
#define ZHUCE_H

#include 

namespace Ui {
class zhuce;
}

class zhuce : public QWidget
{
    Q_OBJECT

public:
    explicit zhuce(QWidget *parent = 0);
    ~zhuce();

private:
    Ui::zhuce *ui;
};

#endif // ZHUCE_H

注意:

1.main.cpp文件不用动

2.zhuce.ui文件和login.ui文件是注册与登录所对应要跳转的新页面

你可能感兴趣的:(qt,qt,命令模式,开发语言)