Q_invokable Vs Public Slot

  
Q_invokable Vs Public Slot 4,9/5 7155 votes
  • PyQt Tutorial
  • PyQt Useful Resources

Components and slots provide similar benefits to sections, layouts, and includes; however, some may find the mental model of components and slots easier to understand. Carrera Digital 12 GT Face Off Digital Electric 1:32 Scale Slot Car Racing Track Set for Racing up to 6 Cars at Once - Includes Two 1:32 Scale Cars & Two Dual-Speed Controllers Ages 8+ 4.4 out of 5 stars 35.

  • Selected Reading

Unlike a console mode application, which is executed in a sequential manner, a GUI based application is event driven. Functions or methods are executed in response to user’s actions like clicking on a button, selecting an item from a collection or a mouse click etc., called events.

Widgets used to build the GUI interface act as the source of such events. Each PyQt widget, which is derived from QObject class, is designed to emit ‘signal’ in response to one or more events. The signal on its own does not perform any action. Instead, it is ‘connected’ to a ‘slot’. The slot can be any callable Python function.

In PyQt, connection between a signal and a slot can be achieved in different ways. Following are most commonly used techniques −

A more convenient way to call a slot_function, when a signal is emitted by a widget is as follows −

Q invocable vs public slot machines

Suppose if a function is to be called when a button is clicked. Here, the clicked signal is to be connected to a callable function. It can be achieved in any of the following two techniques −

or

Example

In the following example, two QPushButton objects (b1 and b2) are added in QDialog window. We want to call functions b1_clicked() and b2_clicked() on clicking b1 and b2 respectively.

When b1 is clicked, the clicked() signal is connected to b1_clicked() function

When b2 is clicked, the clicked() signal is connected to b2_clicked() function

Example

Q_invokable Vs Public Slot

The above code produces the following output −

Q Invocable Vs Public Slot Machines

Output