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:54] – mithat | qt:wiring_up_signals_and_slots [2011/04/01 11:13] – [Creating signal→slot connections] mithat | ||
---|---|---|---|
Line 2: | Line 2: | ||
===== Creating signal→slot connections ===== | ===== Creating signal→slot connections ===== | ||
- | Qt uses a signals and slots system to process events. If you use Qt Creator for development, | + | Qt uses a [[signals and slots]] system to process events. If you use Qt Creator for development, |
- | * Create an "event handler" | + | * [[#Create an "event handler" |
- | * Do it " | + | * [[#Do it " |
- | * Do it in the *.ui file | + | * [[#Do it in the *.ui file]] |
- | * Do it in the constructor | + | * [[#Do it in the constructor |
- | If you use Qt Designer with some other IDE for development, | + | If you use Qt Designer with some other IDE for development, |
==== Create an "event handler" | ==== Create an "event handler" | ||
Line 16: | Line 16: | ||
A handler you make this way for a '' | A handler you make this way for a '' | ||
- | <code cpp> | + | <code cpp-qt> |
void MainWindow:: | void MainWindow:: | ||
{ | { | ||
Line 23: | Line 23: | ||
The handlers you create this way are actually a private slots. You can confirm this by looking at the header file for the class you are editing: | The handlers you create this way are actually a private slots. You can confirm this by looking at the header file for the class you are editing: | ||
- | <code cpp> | + | <code cpp-qt> |
private slots: | private slots: | ||
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 '' |
+ | <code cpp-qt>< | ||
+ | == 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 " | ==== Do it " | ||
Line 89: | Line 94: | ||
// | // | ||
- | If your project uses '' | + | If your project uses '' |
- | + | <code xml> | |
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
==== Do it in the constructor ==== | ==== Do it in the constructor ==== | ||
// | // | ||
Line 96: | Line 110: | ||
You can explicitly connect signals and slots programatically. This is typically done in a form's constructor. | You can explicitly connect signals and slots programatically. This is typically done in a form's constructor. | ||
- | <code cpp> | + | <code cpp-qt> |
HelloForm:: | HelloForm:: | ||
{ | { | ||
widget.setupUi(this); | widget.setupUi(this); | ||
- | connect(widget.button_quit, | + | connect(widget.button_quit, |
- | | + | |
}</ | }</ | ||
===== Runtime signal→slot connection modifications ===== | ===== Runtime signal→slot connection modifications ===== | ||
I don't know. But it should be possible. | 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