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:
parent
f5cc98dc8a
commit
97817f0474
@ -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()) {
|
||||
|
@ -41,6 +41,8 @@ public:
|
||||
|
||||
static Plasma::StorageThread *self();
|
||||
|
||||
void closeDb();
|
||||
|
||||
public Q_SLOTS:
|
||||
void save(QWeakPointer<StorageJob> caller, const QVariantHash ¶meters);
|
||||
void retrieve(QWeakPointer<StorageJob> caller, const QVariantHash ¶meters);
|
||||
|
Loading…
Reference in New Issue
Block a user