@@ -140,12 +140,14 @@ QSqlDatabase QgsAuthManager::authDatabaseConnection() const
140
140
// triggers a condition in QSqlDatabase which detects the nullptr private thread data and returns an invalid database instead.
141
141
// QSqlDatabase::removeDatabase is thread safe, so this is ok to do.
142
142
// Right about now is a good time to re-evaluate your selected career ;)
143
- connect ( QThread::currentThread (), &QThread::finished, QThread::currentThread (), [connectionName, this ]
143
+ QMetaObject::Connection connection = connect ( QThread::currentThread (), &QThread::finished, QThread::currentThread (), [connectionName, this ]
144
144
{
145
145
QMutexLocker locker ( mMutex );
146
- QgsDebugMsgLevel ( QStringLiteral ( " Removing outdated connection to %1 on thread exit" ).arg ( connectionName ), 2 );
147
146
QSqlDatabase::removeDatabase ( connectionName );
147
+ mConnectedThreads .remove ( QThread::currentThread () );
148
148
}, Qt::DirectConnection );
149
+
150
+ mConnectedThreads .insert ( QThread::currentThread (), connection );
149
151
}
150
152
}
151
153
else
@@ -2961,6 +2963,15 @@ void QgsAuthManager::tryToStartDbErase()
2961
2963
2962
2964
QgsAuthManager::~QgsAuthManager ()
2963
2965
{
2966
+ QMutexLocker locker ( mMutex );
2967
+ QMapIterator<QThread *, QMetaObject::Connection> iterator ( mConnectedThreads );
2968
+ while ( iterator.hasNext () )
2969
+ {
2970
+ iterator.next ();
2971
+ iterator.key ()->disconnect ( iterator.value () );
2972
+ }
2973
+ locker.unlock ();
2974
+
2964
2975
if ( !isDisabled () )
2965
2976
{
2966
2977
delete QgsAuthMethodRegistry::instance ();
0 commit comments