Bug report #11207

attributeEditorElements behavior in pyqgis

Added by gillian milani about 10 years ago. Updated about 10 years ago.

Status:Closed
Priority:Normal
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

Description

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

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

Associated revisions

Revision bb3ead3b
Added by Matthias Kuhn about 10 years ago

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

Fix #11207

History

#1 Updated by Matthias Kuhn about 10 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 about 10 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 about 10 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 about 10 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 about 10 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 about 10 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.

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

#7 Updated by Matthias Kuhn about 10 years ago

  • Status changed from Feedback to Closed

#8 Updated by Matthias Kuhn about 10 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