[Qgis-developer] problem with forms and python init function

Luca Lanteri mescal72 at gmail.com
Fri Dec 20 03:03:44 PST 2013


Hi to all,

I'm a newbie with pyqgis so apologize me for the trivial question. I'm
trying to create a forms using QT and to add some intelligence into it
using the "python Init function", present in the Layer properties ->
field menu. I want to update the data in combo2 on the base of the
combo1 choosed value, but I encountered some problem, probably due to
my lack of knowled of QGIS API. This is my first problems:

I try to read some data from a layer using this code [1]. If the layer
is a geometry layer all works fine but if I try to read the data from
a table (without geom coloumn) i cant read the attributes. Both object
are QgsVectorLayer so I though that I can use the same methods. In
order to resolve this problem i just addes a geom coloum to my table
but it's just a ploy.

The second, and the very real problem, is that when I try to update
the the value using the
curLayer.changeAttributeValue() method some strange beaviours occours.
- If i try to commit changes from the code (using
curLayer.commitChanges() ), and I'm in the table form view, Qgis
crash.
- when I try to commit changes use the toogle editing mode button, and
I'm in the table form view, all my changes are lost.
- when I try to commit changes use the toogle editing mode button, and
I'm just in the form view, changes are lost alternatively once on two
saving operation.

I don't understand if this is a problem of my code or a qgis bug.
Any hint ?

I hope to have described the problem clearly.
thank in advance

Luca


[1]
alegend = iface.legendInterface()
allLayers=alegend.layers()
    for i in allLayers:
        if i.name()=='mytab':
            aLayer=i
lista=[]
rsTipo=[]
for i in afeature:
        a=i.attributes()
        l1=i.attributes()[0]
        l2=i.attributes()[1]
        l3=i.attributes()[2]
        l4=i.attributes()[3]
        alist=[l1,l2,l3,l4]
        rsTipo.append(alist)


More information about the Qgis-developer mailing list