Skip to content

Commit 1eb836c

Browse files
committedJan 18, 2017
Avoid startup error when project template folder does not exist
1 parent c80e5d1 commit 1eb836c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,11 +778,20 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
778778
functionProfile( &QgisApp::legendLayerSelectionChanged, this, QStringLiteral( "Legend layer selection changed" ) );
779779
mSaveRollbackInProgress = false;
780780

781-
QFileSystemWatcher* projectsTemplateWatcher = new QFileSystemWatcher( this );
782781
QString templateDirName = settings.value( QStringLiteral( "/qgis/projectTemplateDir" ),
783782
QgsApplication::qgisSettingsDirPath() + "project_templates" ).toString();
784-
projectsTemplateWatcher->addPath( templateDirName );
785-
connect( projectsTemplateWatcher, SIGNAL( directoryChanged( QString ) ), this, SLOT( updateProjectFromTemplates() ) );
783+
if ( !QFileInfo::exists( templateDirName ) )
784+
{
785+
// create default template directory
786+
if ( !QDir().mkdir( QgsApplication::qgisSettingsDirPath() + "project_templates" ) )
787+
templateDirName.clear();
788+
}
789+
if ( !templateDirName.isEmpty() ) // template directory exists, so watch it!
790+
{
791+
QFileSystemWatcher* projectsTemplateWatcher = new QFileSystemWatcher( this );
792+
projectsTemplateWatcher->addPath( templateDirName );
793+
connect( projectsTemplateWatcher, &QFileSystemWatcher::directoryChanged, this, [this] { updateProjectFromTemplates(); } );
794+
}
786795

787796
// initialize the plugin manager
788797
startProfile( QStringLiteral( "Plugin manager" ) );

0 commit comments

Comments
 (0)