Skip to content
Permalink
Browse files

Fix crash when accessing auth manager when no QgsApplication is avail…

…able
  • Loading branch information
nyalldawson committed Nov 6, 2017
1 parent 7cfbb6f commit c413f147bfb749568d32eee7ce1bc35d77ff499d
Showing with 20 additions and 3 deletions.
  1. +14 −3 src/core/qgsapplication.cpp
  2. +3 −0 src/core/qgsapplication.h
  3. +3 −0 tests/src/python/test_qgsnoapplication.py
@@ -111,6 +111,7 @@ const char *QgsApplication::QGIS_ORGANIZATION_DOMAIN = "qgis.org";
const char *QgsApplication::QGIS_APPLICATION_NAME = "QGIS3";

QgsApplication::ApplicationMembers *QgsApplication::sApplicationMembers = nullptr;
QgsAuthManager *QgsApplication::sAuthManager = nullptr;

QgsApplication::QgsApplication( int &argc, char **argv, bool GUIenabled, const QString &profileFolder, const QString &platformName )
: QApplication( argc, argv, GUIenabled )
@@ -889,11 +890,21 @@ void QgsApplication::initQgis()

QgsAuthManager *QgsApplication::authManager()
{
if ( ! instance()->mAuthManager )
if ( instance() )
{
if ( !instance()->mAuthManager )
{
instance()->mAuthManager = QgsAuthManager::instance();
}
return instance()->mAuthManager;
}
else
{
instance()->mAuthManager = QgsAuthManager::instance();
// no QgsApplication instance
if ( !sAuthManager )
sAuthManager = QgsAuthManager::instance();
return sAuthManager;
}
return instance()->mAuthManager;
}


@@ -749,7 +749,10 @@ class CORE_EXPORT QgsApplication : public QApplication
QMap<QString, QIcon> mIconCache;

QgsDataItemProviderRegistry *mDataItemProviderRegistry = nullptr;

QgsAuthManager *mAuthManager = nullptr;
// ... but in case QgsApplication is never instantiated (eg with custom designer widgets), we fall back to static instance
static QgsAuthManager *sAuthManager;

struct ApplicationMembers
{
@@ -53,6 +53,9 @@ def testNullRepresentation(self):
QgsApplication.setNullRepresentation(nr)
self.assertEqual(QgsApplication.nullRepresentation(), nr)

def testAuthManager(self):
self.assertTrue(QgsApplication.authManager())


if __name__ == '__main__':
unittest.main()

0 comments on commit c413f14

Please sign in to comment.
You can’t perform that action at this time.