Skip to content

Commit 3207600

Browse files
committed
Don't call init in QgsApplication
1 parent 9198971 commit 3207600

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/app/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,8 @@ int main( int argc, char *argv[] )
798798
QCoreApplication::setAttribute( Qt::AA_DisableWindowContextHelpButton, true );
799799
#endif
800800

801-
QApplication *subapp = new QApplication(argc, argv);
801+
QgsApplication myApp( argc, argv, myUseGuiFlag );
802+
802803
// SetUp the QgsSettings Global Settings:
803804
// - use the path specified with --globalsettingsfile path,
804805
// - use the environment if not found
@@ -851,7 +852,6 @@ int main( int argc, char *argv[] )
851852
}
852853
}
853854
delete globalSettings;
854-
delete subapp;
855855

856856
QgsDebugMsg( "CONFIG LOCAL STORAGE:" + configLocalStorageLocation );
857857

@@ -872,7 +872,7 @@ int main( int argc, char *argv[] )
872872
QgsDebugMsg( QString( "\t - %1" ).arg( profileFolder ) );
873873
QgsDebugMsg( QString( "\t - %1" ).arg( rootProfileFolder ) );
874874

875-
QgsApplication myApp( argc, argv, myUseGuiFlag, profileFolder );
875+
myApp.init( profileFolder );
876876

877877
// Settings migration is only supported on the default profile for now.
878878
if ( profileName == "default" )

src/core/qgsapplication.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ QString ABISYM( QgsApplication::mLibraryPath );
9191
QString ABISYM( QgsApplication::mLibexecPath );
9292
QString ABISYM( QgsApplication::mThemeName );
9393
QString ABISYM( QgsApplication::mUIThemeName );
94+
QString ABISYM( QgsApplication::mProfilePath );
95+
9496
QStringList ABISYM( QgsApplication::mDefaultSvgPaths );
9597
QMap<QString, QString> ABISYM( QgsApplication::mSystemEnvVars );
9698
QString ABISYM( QgsApplication::mConfigPath );
99+
100+
bool ABISYM( QgsApplication::mInitialized ) = false;
97101
bool ABISYM( QgsApplication::mRunningFromBuildDir ) = false;
98102
QString ABISYM( QgsApplication::mBuildSourcePath );
99103
#ifdef _MSC_VER
@@ -121,7 +125,7 @@ QgsApplication::QgsApplication( int &argc, char **argv, bool GUIenabled, const Q
121125

122126
mApplicationMembers = new ApplicationMembers();
123127

124-
init( profileFolder ); // init can also be called directly by e.g. unit tests that don't inherit QApplication.
128+
ABISYM( mProfilePath ) = profileFolder;
125129
}
126130

127131
void QgsApplication::init( QString profileFolder )
@@ -146,6 +150,8 @@ void QgsApplication::init( QString profileFolder )
146150
delete profile;
147151
}
148152

153+
ABISYM( mProfilePath ) = profileFolder;
154+
149155
qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );
150156
qRegisterMetaType<QgsProcessingFeatureSourceDefinition>( "QgsProcessingFeatureSourceDefinition" );
151157
qRegisterMetaType<QgsProcessingOutputLayerDefinition>( "QgsProcessingOutputLayerDefinition" );
@@ -259,6 +265,8 @@ void QgsApplication::init( QString profileFolder )
259265
// this should be read from QgsSettings but we don't know where they are at this point
260266
// so we read actual value in main.cpp
261267
ABISYM( mMaxThreads ) = -1;
268+
269+
ABISYM( mInitialized ) = true;
262270
}
263271

264272
QgsApplication::~QgsApplication()
@@ -589,14 +597,14 @@ QString QgsApplication::resolvePkgPath()
589597
Q_FOREACH ( const QString &path, QStringList() << "" << "/.." << "/bin" << "/../../.." )
590598
{
591599
f.setFileName( prefixPath + path + "/qgisbuildpath.txt" );
592-
QgsDebugMsg(f.fileName());
600+
QgsDebugMsg( f.fileName() );
593601
if ( f.exists() )
594602
break;
595603
}
596604

597605
if ( f.exists() && f.open( QIODevice::ReadOnly ) )
598606
{
599-
QgsDebugMsg("Running from build dir!");
607+
QgsDebugMsg( "Running from build dir!" );
600608
return f.readLine().trimmed();
601609
}
602610
else
@@ -980,6 +988,11 @@ QgsApplication::endian_t QgsApplication::endian()
980988

981989
void QgsApplication::initQgis()
982990
{
991+
if ( !ABISYM( mInitialized ) )
992+
{
993+
init( ABISYM( mProfilePath ) );
994+
}
995+
983996
// set the provider plugin path (this creates provider registry)
984997
QgsProviderRegistry::instance( pluginPath() );
985998

src/core/qgsapplication.h

+3
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ class CORE_EXPORT QgsApplication : public QApplication
734734
static QObject *ABISYM( mFileOpenEventReceiver );
735735
static QStringList ABISYM( mFileOpenEventList );
736736

737+
static QString ABISYM( mProfilePath );
737738
static QString ABISYM( mUIThemeName );
738739
static QString ABISYM( mPrefixPath );
739740
static QString ABISYM( mPluginPath );
@@ -746,6 +747,8 @@ class CORE_EXPORT QgsApplication : public QApplication
746747

747748
static QString ABISYM( mConfigPath );
748749

750+
static bool ABISYM( mInitialized );
751+
749752
//! True when running from build directory, i.e. without 'make install'
750753
static bool ABISYM( mRunningFromBuildDir );
751754
//! Path to the source directory. valid only when running from build directory.

0 commit comments

Comments
 (0)