Skip to main content
added 173 characters in body
Source Link
dakcarto
  • 7.8k
  • 27
  • 34

Yes, you can store settings in separate files/ways with QSettings, and within the same Q(Core)Application. This makes it ideal for what you are looking to do.

When initializing your PyQGIS plugin's QSettings, you will want to do something like this for a standard settings setup:

my_settings = QtCore.QSettings(QtCore.QSettings.IniFormat,
                               QtCore.QSettings.UserScope,
                               'MyOrganization', 'MyApp')

Or for a standalone file setup:

my_settings = QtCore.QSettings("/path/to/mysettings.ini",
                               QtCore.QSettings.IniFormat)

Edit: if you are going to use a standalone file, consider storing it in the QgsApplication.qgisSettingsDirPath() directory, e.g. usually resolves to ~/.qgis2/.

What you DO NOT want to do, like many PyQGIS plugin developers have often done, is the following:

my_settings = QtCore.QSettings()

Since your plugin is running inside of an existing QApplication, this will (probably) return a reference to QGIS's QSettings object, which is not necessarily a good place to store plugin settings. Users are often apt to remove those settings in an attempt to fix an issue with the application.

Yes, you can store settings in separate files/ways with QSettings, and within the same Q(Core)Application. This makes it ideal for what you are looking to do.

When initializing your PyQGIS plugin's QSettings, you will want to do something like this for a standard settings setup:

my_settings = QtCore.QSettings(QtCore.QSettings.IniFormat,
                               QtCore.QSettings.UserScope,
                               'MyOrganization', 'MyApp')

Or for a standalone file setup:

my_settings = QtCore.QSettings("/path/to/mysettings.ini",
                               QtCore.QSettings.IniFormat)

What you DO NOT want to do, like many PyQGIS plugin developers have often done, is the following:

my_settings = QtCore.QSettings()

Since your plugin is running inside of an existing QApplication, this will (probably) return a reference to QGIS's QSettings object, which is not necessarily a good place to store plugin settings. Users are often apt to remove those settings in an attempt to fix an issue with the application.

Yes, you can store settings in separate files/ways with QSettings, and within the same Q(Core)Application. This makes it ideal for what you are looking to do.

When initializing your PyQGIS plugin's QSettings, you will want to do something like this for a standard settings setup:

my_settings = QtCore.QSettings(QtCore.QSettings.IniFormat,
                               QtCore.QSettings.UserScope,
                               'MyOrganization', 'MyApp')

Or for a standalone file setup:

my_settings = QtCore.QSettings("/path/to/mysettings.ini",
                               QtCore.QSettings.IniFormat)

Edit: if you are going to use a standalone file, consider storing it in the QgsApplication.qgisSettingsDirPath() directory, e.g. usually resolves to ~/.qgis2/.

What you DO NOT want to do, like many PyQGIS plugin developers have often done, is the following:

my_settings = QtCore.QSettings()

Since your plugin is running inside of an existing QApplication, this will (probably) return a reference to QGIS's QSettings object, which is not necessarily a good place to store plugin settings. Users are often apt to remove those settings in an attempt to fix an issue with the application.

Source Link
dakcarto
  • 7.8k
  • 27
  • 34

Yes, you can store settings in separate files/ways with QSettings, and within the same Q(Core)Application. This makes it ideal for what you are looking to do.

When initializing your PyQGIS plugin's QSettings, you will want to do something like this for a standard settings setup:

my_settings = QtCore.QSettings(QtCore.QSettings.IniFormat,
                               QtCore.QSettings.UserScope,
                               'MyOrganization', 'MyApp')

Or for a standalone file setup:

my_settings = QtCore.QSettings("/path/to/mysettings.ini",
                               QtCore.QSettings.IniFormat)

What you DO NOT want to do, like many PyQGIS plugin developers have often done, is the following:

my_settings = QtCore.QSettings()

Since your plugin is running inside of an existing QApplication, this will (probably) return a reference to QGIS's QSettings object, which is not necessarily a good place to store plugin settings. Users are often apt to remove those settings in an attempt to fix an issue with the application.