1

Qgis version : 2.18.1 I was having trouble when launching a custom edit form because of my use of feature in the formOpen method. I want to get an attribute from the current feature as this:

feature.attributes()[1]

I thought it was intended to reference the current feature that was edited and it kinda does it but when I print feature and it's id() it displays every time two feature objects one with id=0 and the second with the correct id. it's not really a big issue because it still works but I get a message each time I launch the form that the list index is out of range. Does anyone know how to fix or at least circumvent this ?

Edit 1: I should precise that i have set a relation widget on this table whith referencing to other features from the same table.

Edit 2: Alright so it seems the problem was deeper and my issue could possibly help others. I wanted to post another problem that arose from this custom form whith python logic but it seems that the two are linked. I've set a widget to plot a graph when a button was clicked, it worked, but stopped after i had set up a relation manager as a widget too, with a relation set on the same layer. That's when the ghost non valid feature problem happened. The thing is that the widget used as the Qgis Relation Manager displays the same dialog so when i asked inside the formOpen(dialog, layer,feature) method to print the current feature id it printed the non valid feature from the Relation Manager (when there wasn't relations) or the children features and then the current feature of the original edit form. The best solution seems to get rid of the Relation Manager when your relations are within the same layer. I think i will replace the Relation Manager by customizing a QListWidget and a QLineEdit except if someone comes with a better idea.

  • I used this : if feature.isValid(): feat = feature fattr = feat.attributes()[1] and it doesn't show the message anymore. – Gingerbread Aug 28 '17 at 8:46

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.