Opened 14 years ago

Closed 14 years ago

#2700 closed bug (fixed)

Adding a layer from py plugin, with QgsVectorLayer.setEditFormInit (QString function) set

Reported by: jaanussuvi Owned by:
Priority: critical: causes crash or data corruption Milestone: Version 1.6.0
Component: Python plugins and bindings Version: 1.4.0
Keywords: QgsVectorLayer setEditFormInit Cc:
Must Fix for Release: No Platform: Windows
Platform Version: Quantum GIS 1.4 - code revision 12728 Awaiting user input: yes

Description

Briefly about my case: I created a python plugin, and it creates QgsVectorLayer's from Postgis database. I do add qml styles to my layers, with layer.loadNamedStyle(path_to_qml). And in qml i've specified form init functions in python <editforminit>myInitMethod</editforminit> I'm trying to initilize some data fields with editforminit function.

The problem:

1) i add a layer with my plugin

2) select the added layer which has <editforminit> specified

3) toggle the layer to edit mode

4) try to add a layer object to map, click on the map

5) then qgis always craches

Problem is only when i have set editforminit function.



but if i do steps

  • (save project)
  • (close and open qgis)

before adding new object to my layer, then editforminit function is invoked and everything works.

Maybe there's a workaround? Maybe some refreshing?

I do after adding layers:

self.iface.refreshLegend(myLayer)

self.iface.mapCanvas().refresh()

Change History (7)

comment:1 by borysiasty, 14 years ago

Owner: borysiasty removed

comment:2 by lutra, 14 years ago

Hi,

feedback to your problem the problem would be better asked in the developer mailing list.

comment:3 by wildintellect, 14 years ago

Must Fix for Release: YesNo

Needs to be retested on a newer trunk, not a showstopper for release.

comment:4 by wonder, 14 years ago

This could have been fixed recently in r13751, please test again.

If the problem persists, please provide further information how to replicate the problem. Can you simply add a layer and set a QML with "editforminit" function to get the crash (without using the plugin)?

comment:5 by brushtyler, 14 years ago

Awaiting user input: set

No user's inputs for 5 weeks... I tick the "awaiting user input" checkbox and hope.

in reply to:  4 comment:6 by jaanussuvi, 14 years ago

Replying to wonder:

This could have been fixed recently in r13751, please test again.

Sorry, I've finished my project with the´plugin, and i do not have development environment setup anymore. So it's really time consuming to test it. btw the plugin doesn't use custom editform or init function. I solved it differently. I think this approach was too complex anyway.

If the problem persists, please provide further information how to replicate the problem. Can you simply add a layer and set a QML with "editforminit" function to get the crash (without using the plugin)?

Yes, if i add a postgis layer to my qgis project with custom editform, then it works fine. But if i add postgis layer with python, and try to add new object to the layer, then it does not work. But if i save newly created layer to gqis project and restart gqis, then it works.

How to replicate: Also complex task, if not having the setup. I believe it could be done with python console.

U should have postgis db and qml for some geo object. in qml of course <editforminit>myInitMethod</editforminit>

Code that creates vector layer from postgis: uri = qgis.core.QgsDataSourceURI() uri.setDataSource("your_schema", "your_geo_table", "the_geom", subset_sql) vl = qgis.core.QgsVectorLayer(uri.uri(), "layer_name", "postgres") vl.loadNamedStyle(QString(qml_path + "vl.qml")) qgis.core.QgsMapLayerRegistry.instance().addMapLayer(vl, True) self.iface.refreshLegend(vl self.iface.mapCanvas().refresh()

Sorry, i'm too busy with new projects. I hope my description helps.

comment:7 by pcav, 14 years ago

Milestone: Version 1.5.0Version 1.6.0
Resolution: fixed
Status: newclosed

Closing it pending reporter check. Please reopen it if necessary.

Note: See TracTickets for help on using tickets.