Bug report #14970

Python QgsAttributeEditor return an error due to mismatch signature with documentation

Added by Thomas Gratier almost 8 years ago. Updated almost 8 years ago.

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

Description

Trying the following Python code

from PyQt4.QtGui import QWidget
from qgis.gui import QgsAttributeEditor
from qgis.utils import iface

w = QWidget()

layer = iface.activeLayer()
attribute_editor = QgsAttributeEditor(w, layer, 0) # Return below error

# Traceback (most recent call last):
#   File "<input>", line 1, in <module>
# TypeError: QgsAttributeEditor(QObject): too many arguments

Error seems to be related to signature mismatch with the documentation e.g http://www.qgis.org/api/classQgsAttributeEditor.html#ae39cfa5a626571cb477ae00ad40c413f

History

#1 Updated by Matthias Kuhn almost 8 years ago

QgsAttributeEditor is deprecated.

Use this code instead

editFormConfig = layer.editFormConfig()
widgetType = editFormConfig.widgetType(idx)
widgetConfig = editFormConfig.widgetConfig(idx)
wrapper = QgsEditorWidgetRegistry::instance().create(widgetType, layer, idx, widgetConfig, None, None)
widget = wrapper.widget()

#2 Updated by Thomas Gratier almost 8 years ago

Thanks for your feedback. I will close the issue.

I will just look more at http://www.qgis.org/api/deprecated.html ;)

#3 Updated by Thomas Gratier almost 8 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF