this is my code :
mydb.cpp
#include <QSqlDatabase>
{
// below are usernames & passwords & ports & etc...
return db;
}
void MyDB::removeConnection()
{
}
#include <QSqlDatabase>
QSqlDatabase MyDB::connectDatabase()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
// below are usernames & passwords & ports & etc...
return db;
}
void MyDB::removeConnection()
{
QSqlDatabase::removeDatabase("QMYSQL");
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mydb.h"
MyDB mydb;
MainWindow::MainWindow()
{
{
// perform queries here
query.clear();
db.close();
}
mydb.removeDatabase(); // not working here
}
#include "mydb.h"
MyDB mydb;
MainWindow::MainWindow()
{
{
QSqlDatabase db = mydb.connectDatabase();
QSqlQuery query;
// perform queries here
query.clear();
db.close();
}
mydb.removeDatabase(); // not working here
}
To copy to clipboard, switch view to plain text mode
i still get this error : QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
what am i missing? i already read the docs about QSqlDatabase::removeDatabase()...
thanks...
Bookmarks