I'm trying to use Qt to connect to a SQlite database as a login window. However when I click the login button it just loops connecting to the server and doesn't send any infomation to it.
My code to connect to the server when the program runs is:
public:
QSqlDatabase mydb;
void connClose()
{
mydb.close();
mydb.removeDatabase(QSqlDatabase::defaultConnection);
}
bool connOpen()
{
mydb=QSqlDatabase::addDatabase("QSQLITE");
mydb.setDatabaseName("C:/Users/Jack/Desktop/Project/SQlite/dataset.db.sqlite");
if(!mydb.open()){
qDebug()<<("Status: Disconnected");
return false;
}
else{
qDebug()<<("Status: Connected");
return true;
}
My code to then attempt to login to the server is:
connOpen();
QSqlQuery loginqry;
loginqry.prepare("select * from login where username='"+username+"' and password='"+password+"'");
if(loginqry.exec()){
int count;
count == 0;
while(loginqry.next()){
count++;
}
if(count==1){
ui->Statuslabel->setText("Login successful");
connClose();
this->hide();
behindlogin behindlogin;
behindlogin.setModal(true);
behindlogin.exec();
}
if(count>1)
ui->Statuslabel->setText("Duplicate usernames and passwords found!");
if(count<1)
ui->Statuslabel->setText("Login unsuccessful");
The error that Qt gives is:
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work. QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed. Status: Connected
Aucun commentaire:
Enregistrer un commentaire