<div dir="ltr">Hi Sergio, <div><br></div><div>DId you fix already your problems? I am not sure if my answer is 100% correct (so I don't post it in stackexchange) as  I didnt try it, but by judging your code:</div><div><span style="font-size:15px"><br></span></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span style="font-size:15px">If I click apply without entering anything in the QLineEdit the QgsMessageBar appears correctly but if I close the QDialog and I do the same the QgisMessageBar has two items (1 more, see picture)</span></blockquote><div><br></div><div>Plugins initiallization happened when starting QGIS. So the plugin is already instantiated (along with your dialog, message bar, etc). Restarting (that is closing and opening again) the dialog in your code doesn't destroy all the instances. That is why the message bar has the previous messages. You can just clear the message bar once user opens the dialog.</div><div><span style="color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;line-height:19.5px;background-color:rgba(248,248,248,0.6)"><br></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span style="color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif;font-size:15px;line-height:19.5px;background-color:rgba(248,248,248,0.6)">If I insert a word in the QLineEdit after opening the plugin for the second time, clicking on apply Qgis crashes.</span></blockquote><div><br></div><div>This is not necessarily related to the crash :p:</div><div><ul><li><pre style="margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;word-wrap:normal;color:rgb(36,39,41);background-color:rgb(239,240,241)"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;white-space:inherit">word = unicode(self.dlg.inputedit.text())</code></pre></li></ul></div>But QString is stored in unicode, no need to recast it</div><div><br></div><div>For the cause of the crash, I strongly believe this is the problem:</div><div><pre style="margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;word-wrap:normal;color:rgb(36,39,41);background-color:rgb(239,240,241)"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;white-space:inherit">    def add_item(self, item):
        self.list.addItem(item)
        return</code></pre></div><div>Can you try to remove return there? I think it's forcing the thread to go back to the main loop (plugin Run method)</div><div><br></div><div>Cheers</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 7, 2016 at 1:57 PM, Sergio Vignali <span dir="ltr"><<a href="mailto:vignalisergio30@gmail.com" target="_blank">vignalisergio30@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>I posted my problem in gis.stackexchange, (<a href="http://gis.stackexchange.com/questions/209602/qgis-crash-using-qthread-in-a-plugin-script" target="_blank">http://gis.stackexchange.com/<wbr>questions/209602/qgis-crash-<wbr>using-qthread-in-a-plugin-<wbr>script</a>).<br>There you can find the full explanation of the problem and all the code I used... It would be great to get some feedbacks!<br></div>Best<br></div>s.<br></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">2016-09-06 3:58 GMT+02:00 Akbar Gumbira <span dir="ltr"><<a href="mailto:akbargumbira@gmail.com" target="_blank">akbargumbira@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">It would be more helpful if you point to the code here. I had a problem with QThread (was initially inheriting QThread) but managed to fix the problem by creating workers and move the worker object to thread. This is a good article about multithreading in qgis<a href="https://snorfalorpagus.net/blog/2013/12/07/multithreading-in-qgis-python-plugins/" target="_blank"> https://snorfalorpagus.net/blo<wbr>g/2013/12/07/multithreading-<wbr>in-qgis-python-plugins/</a></p>
<div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Sep 5, 2016 23:01, "Sergio Vignali" <<a href="mailto:vignalisergio30@gmail.com" target="_blank">vignalisergio30@gmail.com</a>> wrote:<br type="attribution"></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div>Dear all,<br><br>I wrote a python script that aims to execute neighbourhood statistics in raster layer. My script uses QThread to update a QList and a QProgressBar and everithing works fine if I run the script from PyCharm, the progressbar and the list are updated. The problem appears when I move my script in a Qgis plugin, the UI appears correctly but clicking OK the software crashes...<br>I am using qgis 2.14 in a linux machine, do you have any advice?<br><br>All the best<br><br></div><br clear="all"><div><div><div><div><br>-- <br><div><div dir="ltr">Sergio Vignali<div><br></div></div></div>
</div></div></div></div></div>
<br></div></div>______________________________<wbr>_________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
List info: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">http://lists.osgeo.org/mailman<wbr>/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">http://lists.osgeo.org/mailman<wbr>/listinfo/qgis-developer</a><br></blockquote></div></div>
</blockquote></div><br><br clear="all"><br></div></div><span class="HOEnZb"><font color="#888888">-- <br><div data-smartmail="gmail_signature"><div dir="ltr">Sergio Vignali<div><br></div></div></div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><p><b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">-------------------</span></b></p><b>Akbar Gumbira </b></div><div><b style="font-size:12.8px"><a href="http://www.akbargumbira.com" target="_blank">www.akbargumbira.com</a></b></div></div></div></div></div>
</div>