<div dir="ltr">Thanks Matthias. Got it. I was just trying to not flood messages to those pals who may not be interested.<br><div class="gmail_extra"><br></div><div class="gmail_extra">Best regards,</div><div class="gmail_extra">Ethan<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 13, 2018 at 6:16 PM, Matthias Kuhn <span dir="ltr"><<a href="mailto:matthias@opengis.ch" target="_blank">matthias@opengis.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Glad you like it :)<br>
<br>
Forwading this answer also to the mailing list for future reference,<br>
Ethan, you need to use "reply to all" in your mail application or other<br>
are not able to follow our conversation (which would be a pity ;) ).<br>
<br>
Best regards<br>
Matthias<br>
<span class=""><br>
On 06/13/2018 12:13 PM, Zhang Qun wrote:<br>
> Wow, i was about to look into the with() statement. It looks much<br>
> better.  Many thanks for the link. <br>
> <br>
> Regards,<br>
> Ethan<br>
> <br>
> <br>
> On Wed, Jun 13, 2018, 6:03 PM Matthias Kuhn <<a href="mailto:matthias@opengis.ch">matthias@opengis.ch</a><br>
</span><span class="">> <mailto:<a href="mailto:matthias@opengis.ch">matthias@opengis.ch</a>>> wrote:<br>
> <br>
>     Hi Ethan,<br>
> <br>
>     there are of course advantages and disadvantages of both methods, but in<br>
>     most cases the QgsVectorLayer ones just "do the right thing", especially<br>
>     when used with a `with` block, see also this post:<br>
> <br>
>     <a href="http://www.opengis.ch/2015/08/12/with-edit-layer/" rel="noreferrer" target="_blank">http://www.opengis.ch/2015/08/<wbr>12/with-edit-layer/</a><br>
> <br>
>     Cheers<br>
>     Matthias<br>
> <br>
>     On 06/13/2018 11:59 AM, Zhang Qun wrote:<br>
>     > Hi Matthias,<br>
>     ><br>
>     > Thanks very much for the instruction. I will try it out. The<br>
>     > dataProvider method seems simpler to me and it can set attributes in<br>
>     > batch as it takes a list as input. The layer method seems only<br>
>     takes one<br>
>     > input. If i want to change 10 attributes of a feature, i have to issue<br>
>     > 10 commands.<br>
>     ><br>
>     > Best regards,<br>
>     > Ethan<br>
>     ><br>
>     ><br>
>     > On Wed, Jun 13, 2018, 5:45 PM Matthias Kuhn <<a href="mailto:matthias@opengis.ch">matthias@opengis.ch</a><br>
>     <mailto:<a href="mailto:matthias@opengis.ch">matthias@opengis.ch</a>><br>
</span><div><div class="h5">>     > <mailto:<a href="mailto:matthias@opengis.ch">matthias@opengis.ch</a> <mailto:<a href="mailto:matthias@opengis.ch">matthias@opengis.ch</a>>>> wrote:<br>
>     ><br>
>     >     Hi Ethan<br>
>     ><br>
>     >     On 06/13/2018 11:18 AM, Zhang Qun wrote:<br>
>     >     > Hi everyone, i"m using QGIS2.18, and trying to change feature<br>
>     >     attributes<br>
>     >     > using the following two methods:<br>
>     >     ><br>
>     >     > *dataProvider:*<br>
>     >     ><br>
>     >     > |attrs<br>
>     >     ={0:"hello",1:123}layer.<wbr>dataProvider().<wbr>changeAttributeValues({fid<br>
>     >     > :attrs })|<br>
>     >     ><br>
>     >     > *layer object:*<br>
>     >     ><br>
>     >     ><br>
>     >   <br>
>      |layer.startEditing()layer.<wbr>changeAttributeValue(fid,<wbr>fieldIndex,value)layer.<wbr>commitChanges()|<br>
>     >     ><br>
>     >     > I keep the attribute table open, and monitor the changes.<br>
>     The first<br>
>     >     > method dataProvider is not able to update the attribute<br>
>     table on the<br>
>     >     > fly, even the "reload table" button on the top menu of the<br>
>     table does<br>
>     >     > not work. I have to re-open the table to see the changes.<br>
>     The second<br>
>     >     > method is working, the attribute table gets instantly updated.<br>
>     >     ><br>
>     >     > I would like to stay with the dataProvider method but not<br>
>     sure how to<br>
>     >     > get instantly updated attribute table?<br>
>     ><br>
>     >     The provider's dataChanged() signal needs to be emitted, I<br>
>     think you can<br>
>     >     directly emit that or call `dataProvider().forceReload()`<wbr>.<br>
>     ><br>
>     >     Out of curiosity, why would you like to stay with the<br>
>     dataProvider <br>
>     >     method?<br>
>     ><br>
>     >     Bests<br>
>     >     Matthias<br>
>     ><br>
>     ><br>
>     >     ><br>
>     >     > Thanks.<br>
>     >     ><br>
>     >     > Best regards,<br>
>     >     > Ethan<br>
>     >     ><br>
>     >     ><br>
>     >     > ______________________________<wbr>_________________<br>
>     >     > QGIS-Developer mailing list<br>
>     >     > <a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br>
>     <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.<wbr>osgeo.org</a>><br>
</div></div>>     <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.<wbr>osgeo.org</a><br>
<span class="">>     <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.<wbr>osgeo.org</a>>><br>
>     >     > List info:<br>
>     <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
>     >     > Unsubscribe:<br>
>     <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
>     >     ><br>
>     >     _____________________________<wbr>__________________<br>
>     >     QGIS-Developer mailing list<br>
>     >     <a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.<wbr>org</a><br>
>     <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.<wbr>osgeo.org</a>><br>
</span>>     <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.<wbr>osgeo.org</a><br>
<div class="HOEnZb"><div class="h5">>     <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.<wbr>osgeo.org</a>>><br>
>     >     List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
>     >     Unsubscribe:<br>
>     <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
>     ><br>
> <br>
</div></div></blockquote></div><br></div></div>