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
|
void Dialog::on_pushButton_clicked()
{
QSqlDatabase mydb = QSqlDatabase::addDatabase("QMYSQL");
mydb.setHostName("localhost");
mydb.setUserName("root");
mydb.setPassword("");
mydb.setDatabaseName("stock");
QSqlQuery qry;
QString username,password;
username=ui->lineEdit->text();
password=ui->lineEdit_2->text();
if(!mydb.open())
{
qDebug()<<"Failed to open the database";
}
if(qry.exec("select * from user where username='"+username+"' and password='"+password+"'"))
{
int count;
while(qry.next())
{
count++;
}
if(count==1)
{ui->label_4->setText("username and password is correct");
}
else {
ui->label_4->setText("username and password is not correct");
}
}
} |
Partager