qt:wiring_up_signals_and_slots
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
qt:wiring_up_signals_and_slots [2011/03/31 12:06] – [Editing signals and slots] mithat | qt:wiring_up_signals_and_slots [2011/03/31 15:02] – mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Wiring up signals and slots ====== | ====== Wiring up signals and slots ====== | ||
- | FIXME: confirm for accuracy. | ||
- | Signals | + | ===== Creating signal→slot connections ===== |
+ | Qt uses a signals | ||
+ | * [[#Create an "event handler" | ||
+ | * [[#Do it " | ||
+ | * [[#Do it in the *.ui file]] | ||
+ | * [[#Do it in the constructor ]] | ||
- | ===== Create an "event handler" | + | If you use Qt Designer with some other IDE for development, |
+ | |||
+ | ==== Create an "event handler" | ||
// | // | ||
Line 21: | Line 27: | ||
void on_button_quit_clicked();</ | void on_button_quit_clicked();</ | ||
- | ==== Behind the scenes ==== | + | === Behind the scenes === |
How does the build system know that that '' | How does the build system know that that '' | ||
+ | == Question == | ||
+ | If the above is true, then it should be possible to create event handlers just by writing code. Two tests are indicated: | ||
+ | * Write the handlers manually in Qt Creator. | ||
+ | * Write the handlers manually in a project managed by something other than Qt Creator. | ||
- | ===== Do it in the UI builder | + | ==== Do it "visually" |
// | // | ||
Line 35: | Line 44: | ||
* toolbar icon: (figure it out from the menu icon) | * toolbar icon: (figure it out from the menu icon) | ||
- | In this mode, you will notice that when you roll over widgets, they turn red and get a thick border. This tells you they are providers of signals. To make a signal/slot connection | + | In this mode, you will notice that when you roll over widgets, they turn red and get a thick border. This tells you they are providers of signals. To make a signal/slot connection: |
- Roll over the widget that will provide the signal. | - Roll over the widget that will provide the signal. | ||
- Click and drag to the widget whose slot you want to connect to. | - Click and drag to the widget whose slot you want to connect to. | ||
Line 41: | Line 50: | ||
- From the dialog that appears, select the desired signal from the left column and the desired slot from the right and click OK. | - From the dialog that appears, select the desired signal from the left column and the desired slot from the right and click OK. | ||
- | If you don't see a slot that you expect, try clicking on the "Show slots inherited from ..." checkbox. IMHO, this should be checked by default, but isn' | + | If you don't see a slot that you expect, try clicking on the "Show slots inherited from ..." checkbox. IMHO, this should be checked by default, but it isn' |
When you set signal/slot connections this way, you will see arrows connecting widgets indicating signal/slot relationships. | When you set signal/slot connections this way, you will see arrows connecting widgets indicating signal/slot relationships. | ||
- | ==== Special cases ==== | + | === Special cases === |
There are a couple special cases that are worth mentioning. | There are a couple special cases that are worth mentioning. | ||
- | === Connecting to the window | + | == Connecting to the window == |
If you want to connect a signal to the slot of a window, just drag onto the window rather than onto another widget. You will know you are connecting to the main window because the slot end of the connector will turn into an electrical earth ground symbol {{: | If you want to connect a signal to the slot of a window, just drag onto the window rather than onto another widget. You will know you are connecting to the main window because the slot end of the connector will turn into an electrical earth ground symbol {{: | ||
- | === Connecting a widget to itself | + | == Connecting a widget to itself == |
You can also connect widgets to themselves. If you do this, you can set up all sorts of hilarity. Sometimes you can even do useful things. | You can also connect widgets to themselves. If you do this, you can set up all sorts of hilarity. Sometimes you can even do useful things. | ||
- | ==== Editing signals and slots ==== | ||
+ | === Editing signals and slots === | ||
You can edit existing signal/slot connections made in Edit Signal/ | You can edit existing signal/slot connections made in Edit Signal/ | ||
You can add new relationships and delete existing ones using the **+** and **–** icons. The **–** icon seems a bit temperamental, | You can add new relationships and delete existing ones using the **+** and **–** icons. The **–** icon seems a bit temperamental, | ||
- | ==== Behind the scenes ==== | + | === Behind the scenes === |
+ | Connections made this way are stored in a form's ''//< | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <hint type=" | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | <hint type=" | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | Note: If you are using Qt Creator to develop your project, the Qt gods discourage you from manually editing '' | ||
+ | ==== Do it in the *.ui file ==== | ||
+ | // | ||
- | + | If your project uses '' | |
- | ===== Do it in the FIXME ===== | + | <code xml> |
- | //Availability: | + | < |
- | + | < | |
- | ===== Do it in the constructor | + | < |
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | ==== Do it in the constructor ==== | ||
// | // | ||
+ | You can explicitly connect signals and slots programatically. This is typically done in a form's constructor. | ||
+ | |||
+ | <code cpp> | ||
+ | HelloForm:: | ||
+ | { | ||
+ | widget.setupUi(this); | ||
+ | |||
+ | connect(widget.button_quit, | ||
+ | }</ | ||
+ | |||
+ | ===== Runtime signal→slot connection modifications ===== | ||
+ | I don't know. But it should be possible. |
qt/wiring_up_signals_and_slots.txt · Last modified: 2011/04/03 13:14 by mithat