Bug report #11207

attributeEditorElements behavior in pyqgis

Added by gillian milani over 7 years ago. Updated over 7 years ago.

Assignee:Matthias Kuhn
Category:Python plugins
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:19517


Following code make the programm doesn't make anything and crash the programm when attributeEditorElements is used (editor Elements are accessed)

tab1 = QgsAttributeEditorContainer("my first tab", layer)
tab2 = QgsAttributeEditorContainer("my secound tab", layer)
container = QgsAttributeEditorContainer("my continer", layer)
widget1 = QgsAttributeEditorField('remark', layer.fieldNameIndex('remark'), layer);
widget2 = QgsAttributeEditorField('id', layer.fieldNameIndex('id'), layer);
widget3 = QgsAttributeEditorField('parcel', layer.fieldNameIndex('parcel'), layer);

Associated revisions

Revision bb3ead3b
Added by Matthias Kuhn over 7 years ago

Transfer ownership of drag-and-drop layout elements in sip

Fix #11207


#1 Updated by Matthias Kuhn over 7 years ago

  • Status changed from Open to Feedback

This works perfectly fine here on latest master (opened the feature form by adding a new feature).

Can you share the demo data or add further information that may help to debug this problem.

#2 Updated by gillian milani over 7 years ago

When i apply this code on one layer, my qgis crash. Not when it's applied, but the when i try to open the properties, or open attribute table, or open form. I'm testing on master

I'm not saying that the drag and drop is not working (works very well), i just say i cannot access the functions from pyqgis. Have you tried the pyqgis way ?

#3 Updated by Matthias Kuhn over 7 years ago

  • Affected QGIS version changed from 2.4.0 to master

I have executed your code in the python console and opened the form by adding a new feature.
What system are you running on?
Can you paste a backtrace?

#4 Updated by gillian milani over 7 years ago

Ok, i've checked and it's working well in the console. However, it's crashing when using this code in a plugin. I'm not able to create a traceback, but the console display the following:

Warning: loading of qt translation failed [/usr/share/qt4/translations/qt_en_US]
Warning: QGraphicsScene::addItem: item has already been added to this scene
QGIS died on signal 11Could not attach to process. If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
No thread selected
No stack.
gdb returned 0
Aborted (core dumped)

I will search further

#5 Updated by gillian milani over 7 years ago

Warning: uint DBusMenuExporterDBus::GetLayout(int, int, const QStringList&, DBusMenuLayoutItem&): Condition failed: menu

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff39de622 in QgsAttributeForm::init() () from /usr/lib/libqgis_gui.so.2.5.0

#6 Updated by gillian milani over 7 years ago

  • Assignee set to Matthias Kuhn

I solved the problem in this way. Can you explain me what happen ? I let the status as feedback, just if you want to act on this problem, if it is one.

self.tab1 = QgsAttributeEditorContainer("my first tab", layer)
self.tab2 = QgsAttributeEditorContainer("my secound tab", layer)
self.container = QgsAttributeEditorContainer("my continer", layer)
self.widget1 = QgsAttributeEditorField('remark', layer.fieldNameIndex('remark'), layer)
self.widget2 = QgsAttributeEditorField('id', layer.fieldNameIndex('id'), layer)
self.widget3 = QgsAttributeEditorField('parcel', layer.fieldNameIndex('parcel'), layer)

#7 Updated by Matthias Kuhn over 7 years ago

  • Status changed from Feedback to Closed

#8 Updated by Matthias Kuhn over 7 years ago

Explanation: it's related to the python garbage collector, that deletes your container and elements when they scope out (in python) although they are still used in C++.

I have committed a fix, it would be very nice if you could test if this works with the original code.

Thank you for reporting.

Also available in: Atom PDF