when using the qxorm to connect the sqlite ....
-
m_DatabaseCurrent = qx::QxSqlDatabase::getSingleton()->getDatabaseCloned();
qx::QxSqlDatabase::getSingleton()->clearAllSettingsForCurrentThread();
//m_DatabaseCurrent.close();
if(QSqlDatabase::database(m_DatabaseCurrent.connectionName()).isOpen()){
QSqlDatabase::database(m_DatabaseCurrent.connectionName()).close();
}
if(QSqlDatabase::contains(m_DatabaseCurrent.connectionName())){
QSqlDatabase::removeDatabase(m_DatabaseCurrent.connectionName());
}the output tips:
QSqlDatabasePrivate::removeDatabase: connection '{4988436d-8dbb-4670-a7f4-f4fb11f8136f}' is still in use, all queries will cease to work.i just tried to close the database and removed the connection .but it failed.i dont know what should i do to solve this problem.
-
Hi,
Don't store QSqlDatabase objects as a member variable.
It's shown in the class documentation. -
so how to get the pointer of the database that Ive connected?
the method that Database() came out the instance of the database,but not the pointer of the instance connected.Am i right? -
@nicker-player
Did you read the documentation where it has a "red, warning box" statingWarning: It is highly recommended that you do not keep a copy of the QSqlDatabase around as a member of a class, as this will prevent the instance from being correctly cleaned up on shutdown. If you need to access an existing QSqlDatabase, it should be accessed with database(). If you chose to have a QSqlDatabase member variable, this needs to be deleted before the QCoreApplication instance is deleted, otherwise it may lead to undefined behavior.
? So don't use
m_DatabaseCurrent = qx::QxSqlDatabase::getSingleton()->getDatabaseCloned();
wherem_DatabaseCurrent
is a class member variable, useQSqlDatabase db = QSqlDatabase::database();
if you want a local variable or justQSqlDatabase::database()
directly. -
but the way u just mentioned could not get what I want.
the qxorm need to use the qsqldatebase pointer from the intance.how can I get the real pointer from the method of QSqlDatabase::database() -
Simply do it like @JonB told you... don't store it as member, don't have an active insance around (which also means no local db instance) when removing the database connection.
-
@nicker-player said in when using the qxorm to connect the sqlite ....:
how can I get the real pointer from the method of QSqlDatabase::database()
Do you know how you get the pointer to an object in C++? This is basic C++.
-
@nicker-player said in when using the qxorm to connect the sqlite ....:
but the way u just mentioned could not get what I want.
the qxorm need to use the qsqldatebase pointer from the intance.how can I get the real pointer from the method of QSqlDatabase::database()Beside the question of @jsulm, which method needing a pointer are you trying to call ?