Qt Thread Slot Signal

Posted : admin On 7/16/2022
Qt Thread Slot Signal Average ratng: 3,4/5 9984 votes
28 Aug 2011 Matteo Mattei pythonpysideqtthread

8BiTs 매일 코딩 홈페이지. (Qt) Cross Thread Signal and Slots - 2 Get Code. Signals and slots are loosely coupled: A class which emits a signal neither knows nor cares which slots receive the signal. Qt's signals and slots mechanism ensures that if you connect a signal to a slot, the slot will be called with the signal's parameters at the right time. Signals and slots can take any number of arguments of any type.

Qt signal slot thread contextQt Thread Slot Signal
  • Qt provides thread support in the form of platform-independent threading classes, a thread-safe way of posting events, and signal-slot connections across threads. This makes it easy to develop portable multithreaded Qt applications and take advantage of multiprocessor machines. Home Articles Programming C/C.
  • The code inside the Worker's slot would then execute in a separate thread. However, you are free to connect the Worker's slots to any signal, from any object, in any thread. It is safe to connect signals and slots across different threads, thanks to a mechanism called queued connections.

In these days I started studying PySide. After some days spent in reading lot of stuff, I thought that a real example could be useful for who intends to start learning PySide as well. In this example I can show you how you can implement a custom signal (MySignal) together with the usage of threads with QThread.

Qt communicate between threads

The following code creates a window with two buttons: the first starts and stop a thread (MyThread) that runs a batch that prints a point in the stdout every seconds continuously. The second button lets you only start another thread (MyLongThread) that prints an asterisk in the stdout every second for 10 seconds.

Qt thread signal slot

This example uses the api version 2 (introduced with PyQt 4.5) to connect signals to slots.

For more information you can look at:

  • QThread documentation: http://doc.qt.nokia.com/latest/qthread.html
  • PySide signals and slots: http://developer.qt.nokia.com/wiki/Signals_and_Slots_in_PySide
  • PyQt api 2 on PySide: http://www.pyside.org/docs/pseps/psep-0101.html
Different

Qt Signal Return Value

Please enable JavaScript to view the comments powered by Disqus.comments powered by

Qt Thread Signal Slot Example

Disqus

Qt Signal Slot Thread Performance

Related Posts