3

I have been tasked with creating a plugin in QGIS that would connect to a PostGiS database, then let the user (based on its user ID) read the attributes of a table for a particular field, then choose based on this selected attribute, another attribute and then add the view to QGIS.

I created my plugin using Plugin Builder.

Then I used QgsCredentials and QgsDataSourceURI to connect to my database. Works fine. I get the users to enter their username and password to connect. It looks like this: enter image description here

Once this step is passed, the user should be able, via combobox, to select the name of their harvest (I am working with gardeners) then the id of the harvest they want to update. The structure I created looks like this: enter image description here

Now, I have been trying to use the QGIS ComboManager and using this post and this blog post (in spanish) as references. This option works perfectly fine when my layers are in the TOC. However, using ComboManager, I feel like it would work only if I have a vector layer in my TOC. But the users won't have access to the full table, only to a spatial view. Maybe QGIS ComboManager is not the right approach.

I get this error:

def_init_(self, widget, comboBox, comboBox_2, initField="NOM_RECOLTE_", options={}):                                                                                            
SyntaxError: invalid syntax

It doesn't seem to like my initField. I checked on this link but I cannot identify my mistake. Does someone can put me on the right track?

  • Seems like a space is missing def__init__ => def _init_ – julsbreakdown Nov 7 '17 at 14:08

Your Answer

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

Browse other questions tagged or ask your own question.