pyqt Using threads with PyQt

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


While some parts of the Qt framework are thread safe, much of it is not. The Qt C++ documentation provides a good overview of which classes are reentrant (can be used to instantiate objects in multiple threads). The following rules are the most widely sought:

  • You cannot create or access a Qt GUI object from outside the main thread (e.g. anything that subclasses QWidget or similar).
  • Even if the Qt class is reentrant, you cannot share access to a Qt object between threads unless the Qt documentation for that class explicitly states that instances are thread safe.
  • You can use QObject.moveToThread() if you need to move a Qt object from one thread to another (does not apply to Qt GUI objects which must always remain in the main thread). But note that the object must not have a parent.

As per this Stack Overflow QA, it is not recommended to use Python threads if your thread intends to interact with PyQt in any way (even if that part of the Qt framework is thread safe).

Got any pyqt Question?