Bug report #2700
Adding a layer from py plugin, with QgsVectorLayer.setEditFormInit (QString function) set
Status: | Closed | ||
---|---|---|---|
Priority: | Low | ||
Assignee: | - | ||
Category: | Python plugins | ||
Affected QGIS version: | Regression?: | No | |
Operating System: | Windows | Easy fix?: | No |
Pull Request or Patch supplied: | Resolution: | fixed | |
Crashes QGIS or corrupts data: | Copied to github as #: | 12760 |
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()
History
#1 Updated by Giovanni Manghi over 14 years ago
Hi,
feedback to your problem the problem would be better asked in the developer mailing list.
#2 Updated by Alex Mandel over 14 years ago
Needs to be retested on a newer trunk, not a showstopper for release.
#3 Updated by Martin Dobias over 14 years ago
This could have been fixed recently in 52a49c90 (SVN r13752), 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)?
#4 Updated by Giuseppe Sucameli over 14 years ago
No user's inputs for 5 weeks...
I tick the "awaiting user input" checkbox and hope.
#5 Updated by jaanussuvi - over 14 years ago
Replying to [comment:4 wonder]:
This could have been fixed recently in 52a49c90 (SVN r13752), 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.
#6 Updated by Paolo Cavallini over 14 years ago
- Resolution set to fixed
- Status changed from Open to Closed
Closing it pending reporter check. Please reopen it if necessary.