Hello Martin,<div><br></div><div>Thanks for your answer. You are right, I was not doing it correctly in the first place.<div><br></div><div>For 1.8 it "worked" cause I was able to swap each QgsField for a QVariant, in 1.9 with the QgsFields that is not possible anymore.</div>
<div><br></div><div>So I have changed it for:</div><div><br></div><div><div>                    if QGis.QGIS_VERSION_INT < 10900: </div><div>                        new_attributes = feature.attributeMap()</div><div>                        for j in range(new_attributes.__len__()):</div>
<div>                            if not provider.defaultValue(j).isNull():</div><div>                                new_attributes[j] = provider.defaultValue(j)</div><div>                        temp_feature.setAttributeMap(new_attributes)</div>
<div>                    else:</div><div>                        new_attributes = feature.attributes()</div><div>                        for j in range(new_attributes.__len__()):</div><div>                            if not provider.defaultValue(j).isNull():</div>
<div>                                new_attributes[j] = provider.defaultValue(j)</div><div>                        temp_feature.setAttributes(new_attributes)</div></div><div><br></div><div>I don't like the repeated code, but I was not sure if checking for QGIS version for each attribute was much better.</div>
<div><br></div><div>Thanks again, and sorry for the time wasted, I know you guys are quite busy.</div><div><br></div><div>Alexandre Neto</div><div><br><div class="gmail_quote">On Wed, Mar 13, 2013 at 8:48 PM, Martin Dobias <span dir="ltr"><<a href="mailto:wonder.sk@gmail.com" target="_blank">wonder.sk@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Alexandre<br>
<br>
On Tue, Mar 12, 2013 at 1:22 AM, Alexandre Neto <<a href="mailto:senhor.neto@gmail.com">senhor.neto@gmail.com</a>> wrote:<br>
> ...<br>
> new_attributes = layer.pendingFields()<br>
><br>
> [...]<br>
<div class="im">><br>
> But when using it in 1.9 I got the following error in the line:<br>
> new_attributes[j] = feature.attributes()[j]<br>
><br>
> Traceback (most recent call last):<br>
>   File "<input>", line x, in <module><br>
> TypeError: QgsFields.__setitem__(): argument 2 has unexpected type<br>
> 'QVariant'<br>
<br>
</div>What are you actually trying to do?<br>
<br>
layer.pendingFields() returns QgsFields instance, which basically acts<br>
as a list of QgsField instances (attribute definitions). Then, you are<br>
trying to assign an attribute value (QVariant) to a field - that's<br>
clearly an error and it is reported correctly. Probably you want to<br>
copy the attributes to another feature?<br>
<span class="HOEnZb"><font color="#888888"><br>
Martin<br>
</font></span></blockquote></div><br></div></div>