Advertisement
Guest User

Untitled

a guest
Mar 10th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. void MainWindow::on_pushButton_clicked()
  2. {
  3.     QString username = ui->text_username->text();
  4.     QString password = ui->text_password->text();
  5.  
  6.     const QString DRIVER("QSQLITE");
  7.  
  8.     if(QSqlDatabase::isDriverAvailable(DRIVER))
  9.     {
  10.         QSqlDatabase db = QSqlDatabase::addDatabase(DRIVER);
  11.  
  12.         db.setDatabaseName("school");
  13.  
  14.         if(!db.open())
  15.             qWarning() << "MainWindow::DatabaseConnect - ERROR: " << db.lastError().text();
  16.     }
  17.     else
  18.         qWarning() << "MainWindow::DatabaseConnect - ERROR: no driver " << DRIVER << " available";
  19.  
  20.     QSqlQuery qry;
  21.  
  22.     if (qry.exec("select * from accounts where username='"+username+"' and password="+password+"'")){
  23.         int count;
  24.         while (qry.next()){
  25.             count++;
  26.         }
  27.         if(count==1){
  28.             //start listwindow.ui
  29.             this->hide();
  30.             listwindow = new ListWindow(this);
  31.             listwindow->show();
  32.         }
  33.         else{
  34.             QMessageBox::warning(this, "Warning", "Password is incorrect");
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement