-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.cpp
55 lines (48 loc) · 1.14 KB
/
widget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "widget.h"
#include "ui_widget.h"
#include "QtSql"
#include "QtDebug"
#include "QMessageBox"
#include "common.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->setWindowTitle(tr("client-login in"));
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_exitBtn_clicked()
{
exit(0);
}
void Widget::on_loginBtn_clicked()
{
bool isOk=false;
QString edit_user = ui->useridEdit->text();
QString edit_passwd = ui->passEdit->text();
QSqlQuery query;
query.exec("select * from user");
while(query.next()) {
QString user = query.value(1).toString();
QString passwd = query.value(2).toString();
if(edit_user == user && edit_passwd == passwd) {
isOk = true;
qDebug()<<"login successfully!";
this->close();
emit showMainWindow();
}
}
#if NEED_LOGIN == 1
if(!isOk){
qDebug()<<"password incorrent!";
QMessageBox::warning(this,"failed to login in ","Password errors or User is not in database");
}
#else
emit showMainWindow();
this->close();
#endif
}