[Qgis-developer] qgis crash using QThread in a plugin script
Akbar Gumbira
akbargumbira at gmail.com
Tue Sep 13 22:38:17 PDT 2016
Just read your code again in stackexchange. If you want to have a new fresh
instance of your dialog every time you open the dialog, you need to
restructure your code. I think you use Plugin Builder and you instantiated
the dialog in the __init__ of the main file. You can remove the run method
and just open the dialog in the action.
On Wed, Sep 14, 2016 at 2:57 AM, Akbar Gumbira <akbargumbira at gmail.com>
wrote:
> Hi Sergio,
>
> It sounds like a new problem. Did removing the return fix the crash
> problem that happened before? As your problem now that it prints double
> letters, I am sure that you just need to clear some component's state
> before running the worker.
>
> Do you have the plugin somewhere on github? If you have, I'll try it myself
>
> Cheers
>
> On Sep 14, 2016 00:07, "Sergio Vignali" <vignalisergio30 at gmail.com> wrote:
>
>> Hi Akbar,
>>
>> as you suggested I removed return but it didn't solve the problem...
>> I don't get it because when I open the dialog the first time I can play
>> with it changing word without problem
>> (I mean that I can insert a new word several time and when I push apply
>> everything works well).
>> I think it's something that I should destroy when closing the dialog...
>> but I don't find what!
>> Two strange behaviours that I found is that sometimes after restarting
>> the dialog if I insert the same word I inserted during the
>> last run the plugin works well or if I change word it writes double
>> items, like digiting "et" it inserts "ee" and "tt" and after it crashes,
>> but how it gets
>> the double letters in the loop?...
>> It's for sure something related to the restarting as if I use the plugin
>> reload it doesn't crash...
>> Any idea? Anyway thanks for your suggestion!
>>
>> All the best
>> s.
>>
>> 2016-09-10 10:42 GMT+02:00 Sergio Vignali <vignalisergio30 at gmail.com>:
>>
>>> Hi Akbar,
>>> thank you for your answer, I'm abroad till Tuesday but I will test it
>>> asap and let you know.
>>> Best
>>>
>>> Il 09/set/2016 05:04, "Akbar Gumbira" <akbargumbira at gmail.com> ha
>>> scritto:
>>>
>>>> Hi Sergio,
>>>>
>>>> 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:
>>>>
>>>> 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)
>>>>
>>>>
>>>> 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.
>>>>
>>>> If I insert a word in the QLineEdit after opening the plugin for the
>>>>> second time, clicking on apply Qgis crashes.
>>>>
>>>>
>>>> This is not necessarily related to the crash :p:
>>>>
>>>> -
>>>>
>>>> word = unicode(self.dlg.inputedit.text())
>>>>
>>>>
>>>> But QString is stored in unicode, no need to recast it
>>>>
>>>> For the cause of the crash, I strongly believe this is the problem:
>>>>
>>>> def add_item(self, item):
>>>> self.list.addItem(item)
>>>> return
>>>>
>>>> Can you try to remove return there? I think it's forcing the thread to
>>>> go back to the main loop (plugin Run method)
>>>>
>>>> Cheers
>>>>
>>>>
>>>>
>>>> On Wed, Sep 7, 2016 at 1:57 PM, Sergio Vignali <
>>>> vignalisergio30 at gmail.com> wrote:
>>>>
>>>>> I posted my problem in gis.stackexchange, (
>>>>> http://gis.stackexchange.com/questions/209602/qgis-crash-us
>>>>> ing-qthread-in-a-plugin-script).
>>>>> There you can find the full explanation of the problem and all the
>>>>> code I used... It would be great to get some feedbacks!
>>>>> Best
>>>>> s.
>>>>>
>>>>> 2016-09-06 3:58 GMT+02:00 Akbar Gumbira <akbargumbira at gmail.com>:
>>>>>
>>>>>> 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
>>>>>> https://snorfalorpagus.net/blog/2013/12/07/multithreading-in
>>>>>> -qgis-python-plugins/
>>>>>>
>>>>>> On Sep 5, 2016 23:01, "Sergio Vignali" <vignalisergio30 at gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Dear all,
>>>>>>>
>>>>>>> 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...
>>>>>>> I am using qgis 2.14 in a linux machine, do you have any advice?
>>>>>>>
>>>>>>> All the best
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Sergio Vignali
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Qgis-developer mailing list
>>>>>>> Qgis-developer at lists.osgeo.org
>>>>>>> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>>>>> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Sergio Vignali
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> *-------------------*
>>>> *Akbar Gumbira *
>>>> *www.akbargumbira.com <http://www.akbargumbira.com>*
>>>>
>>>
>>
>>
>> --
>> Sergio Vignali
>>
>>
--
*-------------------*
*Akbar Gumbira *
*www.akbargumbira.com <http://www.akbargumbira.com>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160914/cac70ba3/attachment-0001.html>
More information about the Qgis-developer
mailing list