close the connection as soon the app is closing

if the connection is closing on thread deletion, the sql plugin is already unloaded, resulting in a crash
This commit is contained in:
Marco Martin 2012-12-21 18:56:00 +01:00
parent f5cc98dc8a
commit 97817f0474
2 changed files with 15 additions and 4 deletions

View File

@ -46,18 +46,20 @@ public:
Q_GLOBAL_STATIC(StorageThreadSingleton, privateStorageThreadSelf)
static void closeConnection()
{
StorageThread::self()->closeDb();
StorageThread::self()->quit();
}
StorageThread::StorageThread(QObject *parent)
: QThread(parent)
{
qAddPostRoutine(closeConnection);
}
StorageThread::~StorageThread()
{
if (!QCoreApplication::closingDown()) {
QString name = m_db.connectionName();
QSqlDatabase::removeDatabase(name);
}
}
Plasma::StorageThread *StorageThread::self()
@ -65,6 +67,13 @@ Plasma::StorageThread *StorageThread::self()
return &privateStorageThreadSelf()->self;
}
void StorageThread::closeDb()
{
QString name = m_db.connectionName();
QSqlDatabase::removeDatabase(name);
m_db = QSqlDatabase();
}
void StorageThread::initializeDb(StorageJob *caller)
{
if (!m_db.open()) {

View File

@ -41,6 +41,8 @@ public:
static Plasma::StorageThread *self();
void closeDb();
public Q_SLOTS:
void save(QWeakPointer<StorageJob> caller, const QVariantHash &parameters);
void retrieve(QWeakPointer<StorageJob> caller, const QVariantHash &parameters);