Unsolved SQlite connection success then failure?
-
I'm trying to connect sqlite databse, but i'm having a confusing issue. I've run qmake and added sql to .pro file and included:
#include <QtSql/QSqlDatabase>
#include <QDebug>
#include <QFileInfo>
#include <QString>
#include <QMessageBox>in the header file.
in my login.cpp i have the following code:
QSqlDatabase db= QSqlDatabase::addDatabase("QSQLITE", "LMS");
db.setDatabaseName("D:/Documents/Sqlite Database/LMS.db");if (db.open()) //ui->db_label->setText("Connected..."); QMessageBox::information(this,"success","success"); else { ui->db_label->setText("Failed to connect"); }
When i run the code i get the message saying success, but once i click ok the application output states database failed to connect.
-
Where do you click ok? Please provide a complete, mimimal! example - from your code we don't see anything which could go wrong here.
-
Hi,
Are you calling
open
from several different classes ? -
@Christian-Ehrlicher
Qmessagebox will display a message if db is open. When i run the code a message box does appear displaying success. I click ok on the message box then the application output states that the database failed to connect right before the window appears. -
@Mocha-Shakea-Khan said in SQlite connection success then failure?:
database failed to connect
Qt does not output such a string. Do you mean your db_label is displaying "Failed to connect"? Please be more precise... and if so it looks like you're calling your function twice.
-
I feel so stupid; i forgot i tried to connect to qodbc in the main.cpp this morning. I deleted the code and every thing is good now.
-
@Mocha-Shakea-Khan
Oh so it was in main where it printed the message and really not related to Sqllite?
Anyway, shit happens, just mark as solved and back to programming :)