qt设计登陆界面进入主界面,登陆时,无论是密码正确或是错误,都会进入下一个界面,不知如何解决
oneform.h
#ifndef ONEFORM_H
#define ONEFORM_H
#include <QWidget>
#include "twoform.h"
namespace Ui {
class oneform;
}
class oneform : public QWidget
{
Q_OBJECT
public:
explicit oneform(QWidget *parent = 0);
~oneform();
private slots:
void doProcessClinckGotoTwoForm(bool);
void doProcessTwoFormRequest(QString);
void on_pushButton_2_clicked();
void on_pushButton_clicked();
private:
Ui::oneform *ui;
twoform t1;
twoform *p_t2;
void Init();
};
#endif // ONEFORM_H
twoform.h
#ifndef TWOFORM_H
#define TWOFORM_H
#include <QWidget>
namespace Ui {
class twoform;
}
class twoform : public QWidget
{
Q_OBJECT
public:
explicit twoform(QWidget *parent = 0);
~twoform();
private slots:
void doProcessClickBackOneForm(bool);
signals:
void SignalShowOneForm(QString);
private:
Ui::twoform *ui;
int clickCount;
void Init();
};
#endif // TWOFORM_H
oneform.cpp
#include "oneform.h"
#include "ui_oneform.h"
#include <QDebug>
#include <QDebug>//第一次登录的打印
#include <QMessageBox>
oneform::oneform(QWidget *parent) :
QWidget(parent),
ui(new Ui::oneform)
{
ui->setupUi(this);
Init();
qDebug()<<"Date:xxxxxxxxxxxx";
}
oneform::~oneform()
{
delete ui;
}
void oneform::Init(){
//处理单击,到达第二个页面
connect(ui->pushButton,SIGNAL(clicked(bool)),
this,SLOT(doProcessClinckGotoTwoForm(bool)));
p_t2 = new twoform();
//接收第二页面的显示请求
connect(p_t2,SIGNAL(SignalShowOneForm(QString)),
this,SLOT(doProcessTwoFormRequest(QString)));
}
/////////////////slots/////////////
void oneform::doProcessClinckGotoTwoForm(bool){
//第一种方式(出现多个2页面)创建第二个页面
//this会使子窗体的父窗体直接显示
//twoform *tf1= new twoform(this);//this会使子窗体的父窗体直接显示
//twoform *tf1= new twoform();
//tf1->show();//出现多个窗体 new多各对象
//第二种方式t1全局对象
//t1.show();//只会出现一个对象
//第三种,指针全局(一个对象)
p_t2->show();
this->hide();//隐藏第一窗体
}
void oneform::doProcessTwoFormRequest(QString str){
qDebug()<< str <<endl;
this->show();
}
//////////////////////////////////
//取消
void oneform::on_pushButton_2_clicked()
{
this->close();
}
//登录
void oneform::on_pushButton_clicked()
{
QString name=ui->line_name->text();
QString passwd=ui->line_passwd->text();
if(name==passwd){
qDebug()<<"登录成功"<<endl;
}
else{
QMessageBox::warning(this,tr("WARNING"),tr("username or password wrong!"),QMessageBox::Yes);
this->ui->line_passwd->clear();//清除密码
this->ui->line_passwd->setFocus();//鼠标回到密码栏
}
}
main.cpp
#include "oneform.h"
#include <QApplication>
#include "twoform.h"////
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
oneform w;
w.show();
return a.exec();
}
后来尝试加入accept()发生错误,显示找不到函数