1

I'm working on a Qgis plugin with python,

I'm creating a feature and I show a feature form to edit the attributes. But after the openFeatureForm function call the program crash and close

line = QgsFeature()
line.setGeometry(QgsGeometry.fromPolyline(transformedLine))
pr = parcoursLayer.dataProvider()
pr.addFeatures([line])
qgis.utils.iface.openFeatureForm(parcoursLayer,line)

this is the message after crash

4
  • Do you get an error message or stack trace?
    – Branco
    Commented Oct 30, 2015 at 12:26
  • What kind of layer is parcoursLayer? OGR? Memory?
    – underdark
    Commented Oct 30, 2015 at 18:15
  • @Branco, i didn't get any message
    – badr.zr
    Commented Nov 4, 2015 at 12:02
  • @underdark, it's not a Memory layer, it's the current layer
    – badr.zr
    Commented Nov 4, 2015 at 12:03

2 Answers 2

1

we are facing the same issue here. It seems related to a bug in PyQt4.

See preloadForm method comment here for a workaround :

http://qgis.org/api/classQgisInterface.html

and here the issue raised to QT / Pyqt 4 by NathanW:

http://forum.qt.io/topic/26562/crash-calling-c-method-using-quiloader-from-pyqt4

0

Before to set geometry of 'transformedLine' try out to print it. This object should have a form similar (if it is projected in meters) to this (for one feature):

[(366179,4.46968e+06), (357711,4.44966e+06), (363870,4.43041e+06), (382100,4.41947e+06), (396590,4.41078e+06)]

A list of QgsPoint.

The another strange thing is in:

pr.addFeatures([line]) 

You are passing a list where it is expected a feature but, the method 'addFeatures' does not exist in QgsDataProvider. It is in QgsVectorLayer. Normally it would be:

feat = QgsFeature()
feat.setGeometry(QgsGeometry.fromPolyline(transformedLine))
feat.setAttributes([1]) #one feature with id = 1; several features in a loop
your_layer.addFeature(feat, True)
1
  • I show the transformedLine and it's a liste of QgsPoint, and I did what you said, but I have the same problem
    – badr.zr
    Commented Nov 4, 2015 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.