Dear All,
I come back to a very popular error-message. I tried out a lot. I RTFM. I have no clue how to avoid the following mesage if dataGrabber is destrouyed.
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
{
Q_OBJECT
public:
explicit dataGrabber
(QObject *parent
= nullptr
);
~dataGrabber();
private:
public slots:
bool openDatabase();
bool closeDatabase();
}
class dataGrabber : public QObject
{
Q_OBJECT
public:
explicit dataGrabber(QObject *parent = nullptr);
~dataGrabber();
private:
QSqlDatabase dB;
QSqlQuery *query;
public slots:
bool openDatabase();
bool closeDatabase();
}
To copy to clipboard, switch view to plain text mode
bool dataGrabber::openDatabase(){
dB.setHostName("localhost");
dB.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};"
"DSN='';DBQ=" + dbPath + ";");
if(dB.open()){
query
= new QSqlQuery(dB
);
// open dB and prepare query prepareQuery();
return true;
{
else{
QMessageBox::warning(0,
"Failure !", dB.
lastError().
text(),
"OK");
return false;
}
return true;
}
bool dataGrabber::openDatabase(){
dB = QSqlDatabase::addDatabase("QODBC");
dB.setHostName("localhost");
dB.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};"
"DSN='';DBQ=" + dbPath + ";");
if(dB.open()){
query = new QSqlQuery(dB); // open dB and prepare query
prepareQuery();
return true;
{
else{
QMessageBox::warning(0, "Failure !", dB.lastError().text(), "OK");
return false;
}
return true;
}
To copy to clipboard, switch view to plain text mode
bool dataGrabber::closeDatabase(){
query->finish();
query->clear();
delete query;
dB.close();
return true;
}
bool dataGrabber::closeDatabase(){
query->finish();
query->clear();
delete query;
dB.close();
return true;
}
To copy to clipboard, switch view to plain text mode
dataGrabber::~dataGrabber(){
dB.removeDatabase("qt_sql_default_connection");
}
dataGrabber::~dataGrabber(){
dB.removeDatabase("qt_sql_default_connection");
}
To copy to clipboard, switch view to plain text mode
As always, every help highly appreciated.
Cheers and thanks.
Bookmarks