我用tabwidget做了2个登陆界面,一个是admin,一个是user,admin登录成功后可以进入第三个页面管理货物,user登录成功后可以进入第四个页面购买货物。。。
这些功能都可以实现,登录成功后都可以弹出新的窗口,但是新的窗口上的按钮点的都没反应,我已经给他们连接了信号和槽,点了按钮后跳出新的窗体,但是都没用,
也就是说只有tabwidget里面的2个登录界面的按钮是有用的。。。新窗体的按钮都没用,这是为什么。。。
#include "mywidget.h"
#include <QtGui/QMessageBox>
#include <QtCore/QString>
#include <QtGui/QIcon>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
setWindowTitle(tr("Welcome to Shopping System"));
QTabWidget *tabWidget = new QTabWidget(this);
QDialog *w2 = new QDialog;
secondUi.setupUi(w2);
QDialog *w3 = new QDialog;
thirdUi.setupUi(w3);
tabWidget->addTab(w2,"admin login");
tabWidget->addTab(w3,"user login");
tabWidget->resize(400,350);
connect(secondUi.pushButton1,SIGNAL(clicked()),this,SLOT(adlogin())); //admin登录成功后进入货物管理界面
connect(secondUi.pushButton2,SIGNAL(clicked()),this,SLOT(close()));
connect(thirdUi.pushButton1,SIGNAL(clicked()),this,SLOT(usrlogin())); //user登录成功后进入购买界面
connect(thirdUi.pushButton2,SIGNAL(clicked()),this,SLOT(close()));
//second和third是两个登陆界面,嵌在tabwidget中,按钮功能正常实现,输入密码可以进入新界面
connect(fifthUi.pushButton1,SIGNAL(clicked()),this,SLOT(buy())); //点击购买按钮进入信息登记界面
connect(fifthUi.pushButton11,SIGNAL(clicked()),this,SLOT(intro())); //弹出新窗口介绍本店
//第五个界面是购买界面,但是这个界面上的按钮都没反应。。。
}
void MyWidget::adlogin()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("d:\\mkyang\\ymk.db");
if(db.open())
{QSqlQuery query;
query.exec("Create table if not exists adlogin(adname VARCHAR(20),"
"password VARCHAR(20))");
query.exec("insert into adlogin values('admin','admin')");
QString s1,s2;
query.exec("select * from adlogin");
while(query.next())
{ s1=query.value(0).toString();
s2=query.value(1).toString();
}
if(secondUi.lineEdit1->text()==s1&&secondUi.lineEdit2->text()==s2)
{ QMessageBox::about(this,tr("Welcome!"),tr("administrator login successfully!"));
QDialog *w4 = new QDialog;
fourthUi.setupUi(w4);
w4->show();
this->hide();
}
else
{
secondUi.lineEdit1->setText("");
secondUi.lineEdit2->setText("");
QMessageBox::about(this,tr("Error!"),tr("Wrong name or password!"));
}
}
else
QMessageBox::about(this,tr("Error!"),tr("database not open!"));
}
void MyWidget::usrlogin()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("d:\\mkyang\\ymk.db");
if(db.open())
{QSqlQuery query;
query.exec("Create table if not exists usrlogin(usrname VARCHAR(20),"
"password VARCHAR(20))");
query.exec("insert into usrlogin values('user','user')");
QString s1,s2;
query.exec("select * from usrlogin");
while(query.next())
{
s1=query.value(0).toString();
s2=query.value(1).toString();
}
if(thirdUi.lineEdit1->text()==s1&&thirdUi.lineEdit2->text()==s2)
{ QMessageBox::about(this,tr("Welcome!"),tr("Wish you pleasant shopping!"));
QDialog *w5 = new QDialog;
fifthUi.setupUi(w5);
w5->show();
this->hide(); }
else
{
thirdUi.lineEdit1->setText("");
thirdUi.lineEdit2->setText("");
QMessageBox::about(this,tr("Error!"),tr("Wrong name or password!"));
}
}
else
QMessageBox::about(this,tr("Error!"),tr("database not open!"));
}
void MyWidget::intro()
{
QDialog *w6 = new QDialog;
sixthUi.setupUi(w6);
w6->show();
}
void MyWidget::buy()
{
QDialog *w7 = new QDialog;
seventhUi.setupUi(w7);
w7->show();
this->hide();
}
在tabwidget的两个登录界面,功能都可以实现,但是进入新的页面后按钮功能却无法实现,这是为什么。。。