Skip to content

Commit f3943f5

Browse files
committed
do not write logs before QgsApplication instace
because otherwise it creates a QgsProject without a QgsApplication and translation won't work anymore because it cannot connect the signal to the slot this fixes #20561
1 parent dcba255 commit f3943f5

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/app/main.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ APP_EXPORT
430430
#endif
431431
int main( int argc, char *argv[] )
432432
{
433+
//log messages written before creating QgsApplicatoin
434+
QStringList preApplicationLogMessages;
435+
433436
#ifdef Q_OS_MACX
434437
// Increase file resource limits (i.e., number of allowed open files)
435438
// (from code provided by Larry Biehl, Purdue University, USA, from 'MultiSpec' project)
@@ -866,11 +869,11 @@ int main( int argc, char *argv[] )
866869
{
867870
if ( !QgsSettings::setGlobalSettingsPath( globalsettingsfile ) )
868871
{
869-
QgsMessageLog::logMessage( QObject::tr( "Invalid globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
872+
preApplicationLogMessages << QObject::tr( "Invalid globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" );
870873
}
871874
else
872875
{
873-
QgsMessageLog::logMessage( QObject::tr( "Successfully loaded globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" ) );
876+
preApplicationLogMessages << QObject::tr( "Successfully loaded globalsettingsfile path: %1" ).arg( globalsettingsfile ), QStringLiteral( "QGIS" );
874877
}
875878
}
876879

@@ -970,6 +973,10 @@ int main( int argc, char *argv[] )
970973

971974
QgsApplication myApp( argc, argv, myUseGuiFlag );
972975

976+
//write the log messages written before creating QgsApplicatoin
977+
for ( QString const &preApplicationLogMessage : preApplicationLogMessages )
978+
QgsMessageLog::logMessage( preApplicationLogMessage );
979+
973980
// Settings migration is only supported on the default profile for now.
974981
if ( profileName == QLatin1String( "default" ) )
975982
{

src/core/qgsproject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ QgsProject::QgsProject( QObject *parent )
384384
connect( mLayerStore.get(), &QgsMapLayerStore::allLayersRemoved, this, &QgsProject::removeAll );
385385
connect( mLayerStore.get(), &QgsMapLayerStore::layersAdded, this, &QgsProject::layersAdded );
386386
connect( mLayerStore.get(), &QgsMapLayerStore::layerWasAdded, this, &QgsProject::layerWasAdded );
387-
if ( QgsApplication::instance() )
388-
connect( QgsApplication::instance(), &QgsApplication::requestForTranslatableObjects, this, &QgsProject::registerTranslatableObjects );
387+
Q_ASSERT( QgsApplication::instance() );
388+
connect( QgsApplication::instance(), &QgsApplication::requestForTranslatableObjects, this, &QgsProject::registerTranslatableObjects );
389389
connect( mLayerStore.get(), static_cast<void ( QgsMapLayerStore::* )( const QList<QgsMapLayer *> & )>( &QgsMapLayerStore::layersWillBeRemoved ),
390390
[ = ]( const QList<QgsMapLayer *> &layers )
391391
{

0 commit comments

Comments
 (0)