Solved use to undeclared identifier on SQL Connecting
-
Hi,i need help.
I got error "use to undeclared identifier" on my code,and im stuck on it.Please help me,im new to QT.Thank You = )\Here is the code:
#include "login.h" #include "ui_login.h" #include "dialog.h" #include <QSqlRecord> QSQLITE::DB db; Login::Login(QWidget *parent) : QMainWindow(parent), ui(new Ui::Login) { ui->setupUi(this); db = QSqlDatabase::addDatabase("QSQLITE"); db.setHostName("localhost"); db.setDatabaseName("login_system"); db.setUserName("root"); db.setPassword(""); if(db.open()) ui->label_4->setText("Connected..."); else ui->label_4->setText("Disconnected..."); } Login::~Login() { delete ui; } void Login::on_pushButton_clicked() { QString username,password; username = ui->lineEdit_username->text(); password = ui->lineEdit_2_password->text(); if(!db.open()) { qDebug()<<"Not Connected to DataBase"; return; } QSqlQuery qry; if(qry.exec("select * from login where username ='"+ username +"' and password='"+password +"'")) { int count=0; if(qry.next()) { count++; } if(count==1){ ui->label_4->setText("Sucessfully logged in"); this->hide(); Dialog dialog; dialog.setModal(true); dialog.exec(); } if(count>1) ui->label_4->setText("Username doesn't seem valid,or the password is wrong.Please try again"); if(count<1) ui->label_4->setText("Username doesn't seem valid,or the password is wrong.Please try again"); } }
The error is appear on line 6: "QSQLITE::DB db;"
-
@ELEMENTICY said in use to undeclared identifier on SQL Connecting:
QSQLITE::DB db;
So what should this be? Please read the documentation on how to open a db connection.
-
@ELEMENTICY said in use to undeclared identifier on SQL Connecting:
QSQLITE::DB db;
So what should this be? Please read the documentation on how to open a db connection.
-
@Christian-Ehrlicher i dont know,i could't find the answer in the doc,im new at c++,please tell me answer.
Appreciate it : ) -
So I would start with a c++ book instead. And I don't need to provide some code as it is written exactly in the documentation I gave you.
-
-
@Christian-Ehrlicher Doing that is good,but.You didt tell me the answer ;/
-
please help :)
-
@ELEMENTICY said in use to undeclared identifier on SQL Connecting:
Doing that is good,but.You didt tell me the answer ;/
I gave the answer to you - my link has a code example which does exactly what you want. See in the details section!