Mini-tutorial on slots and signals

This mini-tutorial from Mark Hammond explains how to use QtDesigner for editing signals-slots connections.

On Figure 1 we have a screen-shot of one of our dialogs in QtDesigner in "Edit Widgets" (ie, normal) mode, with a signal/slot editor to the right. This little editor is generally in the tabbed window to the right of the screen, right near the Property Editor. Select "Tools->Signal/Slot Editor" to ensure it is visible.

slot-signal-fig1.png

Figure 1

Let's go through this list:

Now - we will switch QtDesigner into "Edit Signals/Slots" mode - select that mode from the Edit menu or press F4. Suddenly we will see lots of colors, see figure 2 below.

slot-signal-fig2.png

Figure 2

Note how Qt is trying to show all these signal slot relationships. Note that when a slot/signal is selected on the right, the connection is shown in pink on the form itself. It looks noisy, but it starts to make sense after a short time.

By way of example, let's say I wanted to add a new label to the form with a new help link. See below figure 3 - I've added a new 'TextLabel' at the bottom of the form and selected it.

slot-signal-fig3.png

Figure 3

Now, I drag a line from that new widget to the dialog itself. A Qt dialog pops up asking me what connection I want to make between the objects. In this case, I want to connect the linkActivated signal from the label with the linkActivated slot on our dialog - see figure 4:

slot-signal-fig4.png

Figure 4

If you select OK, the Signal/Slot editor panel we started with will now show this new connection.