diff --git a/src/providers/postgres/qgspostgresconn.cpp b/src/providers/postgres/qgspostgresconn.cpp index 7290137aaed..cdf7e20e4c7 100644 --- a/src/providers/postgres/qgspostgresconn.cpp +++ b/src/providers/postgres/qgspostgresconn.cpp @@ -270,7 +270,7 @@ void QgsPostgresConn::disconnect() Q_ASSERT( !key.isNull() ); connections.remove( key ); - if ( QThread::currentThread() == QApplication::instance()->thread() ) + if ( !QApplication::instance() || QThread::currentThread() == QApplication::instance()->thread() ) deleteLater(); else delete this;