[PyQt] Show QDialog and execute code after

Kyle Altendorf sda at fstab.net
Sun Apr 15 13:20:42 BST 2018



On April 15, 2018 3:55:14 AM EDT, Barry <barry at barrys-emacs.org> wrote:
>
>
>> On 14 Apr 2018, at 20:46, Ricardo Araoz <ricaraoz at gmail.com> wrote:
>> 
>>> On 14/04/18 15:46, Kyle Altendorf wrote:
>>> On April 14, 2018 2:01:36 PM EDT, Maurizio Berti
><maurizio.berti at gmail.com> wrote:
>>>>> I making an update app that shows a QTextEdit object and starts
>>>> (should)
>>>> start to get information from the system before
>>>>> ask the user what to do, it does that but if now but only after
>the
>>>> function get all the system info and the it draws the QDialog.
>>>>> It's something like a Debian apt-get where the terminal is showing
>>>> what
>>>> is appending before and after each operation.
>>>> 
>>>> If that's the case, you should use a separate QObject that collects
>the
>>>> output of apt-get and emits a signal every time it has something to
>>>> show.
>>>> That QObject has to be moved to a new QThread, so that the apt-get
>>>> process
>>>> will not block the GUI interaction and painting.
>
>Is there any advantage to using QThread over python threads?

They get you an event loop in the thread (so long as you use them properly for that) which is required to receive signals (along with not blocking the event loop, just as you shouldn't in the main thread).

Mostly I look for options other than threads. There are various for various needs between Qt and Python. This includes async/inlineCallbacks functions which allow you to write async code without breaking it up and connecting with signals and slots which is a pain when sequencing stuff.

Cheers,
-kyle


More information about the PyQt mailing list