3

I have a plugin for QGIS that helps to populate databases. The user has the option to create a new database or to use an existing connection. If the user chooses to make a new database, I would also like to add this database as a new connection in the browser panel :

enter image description here

I can find lots of help on connecting to the database, which I have been able to do, but nothing for how to add a new connection. Is this possible?

3

I figured it out myself in the end. The database connection information is stored in PyQt4.QtCore.QSettings().

Using this page: http://pyqt.sourceforge.net/Docs/PyQt4/pyqt_qsettings.html

I was able to add all of the required properties & credentials to the connection list.

  • is passing sensitive credentials such as password safe in this case ? – Abhijit Gujar Dec 28 '18 at 15:48
  • @AbhijitGujar the credentials are stored as plain text in the QGIS configuration file itself, which is not secure, but it requires that a user has already saved the connection and explicitly stated to do so. I think there is a clear warning popup in QGIS that advises against doing this for sensitive connections. – wfgeo Jan 4 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.