Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "loginwindow.h"
- #include "ui_loginwindow.h"
- #include "definitions.cpp"
- #include "mainwindow.h"
- LoginWindow::LoginWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::LoginWindow)
- {
- ui->setupUi(this);
- usersBase = QSqlDatabase::addDatabase("QSQLITE");
- usersBase.setDatabaseName("userDataBase.db");
- if(!usersBase.open())
- ui->dataLabel->setText("Failed to connect");
- else
- ui->dataLabel->setText("Connected to the data base");
- }
- LoginWindow::~LoginWindow()
- {
- delete ui;
- }
- void LoginWindow::on_pushButton_clicked()
- {
- QString nick, password;
- nick = ui->loginLine->text();
- password = ui->passwordLine->text();
- if(!usersBase.isOpen())
- {
- qDebug()<<"Failed to open the database";
- return;
- }
- QSqlQuery qry;
- if(qry.exec("select * from Users where Nick = '"+nick+"' and Password = '"+password+"'" ))
- {
- int count = 0;
- while(qry.next())
- {
- count++;
- }
- if(count == 1)
- {
- // string nick_str = nick.toStdString();
- close();
- if((nick.toStdString()) == admin.nick)
- {
- MainWindow mainWindow;
- user = &admin;
- mainWindow.show();
- }
- if((nick.toStdString()) == student.nick)
- {
- user = &student;
- }
- if((nick.toStdString()) == professor.nick)
- {
- user = &professor;
- }
- usersBase.close();
- }
- if(count < 1)
- {
- ui->errorLabel->setText("Wrong login or password");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement