SaveFocusWidget is a slot which will be called whenever focus changes, and allows us to store the newly focused widget in lastFocusedWidget, so that its focus can be restored if it loses it to the input panel. ButtonClicked is a slot which will be called by the signalMapper whenever it receives a clicked signal from any of the buttons. QSignalMapper's mapslot is invoked (thanks to the connectcall in the forloop). If a mapping exists for the object that emitted the signal, the mapped(int)signal is emitted with the integer value set using setMapping. That signal is in.
I try to understand the QSignalMapper and to do some proper work with it but there are some pieces of code I see almost everywhere but don't really get:
@connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));@
What is the
@SLOT(map())@
used for and by what could it be replaced with? Or is it necessary to have exactly that method here?
If I'm not completely wrong 'connect(...)' connects a Signal to either a slot or a signal. And if my preferred signal hasn't got the parameters I need in the Slot I use the QSignalMapper?
With using
@signalMapper->setMapping(button, const QString &);@
I 'pretend' (or better: QT behaves as) the signal @clicked()@
had a QString-paramter, right?
Most tutorials have in the end of their snipplets another line with this ominous map()-Function:
@connect(signalMapper, SIGNAL(mapped(const QString &)), this, SIGNAL(clicked(const QString &)));@
I get the first paramter. signalMapper is used because it's the Object of action, right?
But how and why did the map()-function become a Signal too? (Usually this line has no comments unfortunately).
The third is clear, that's the parent...
But since when does the clicked-Signal really have a QString as parameter...?
I'd be thankful if someone could help me with understanding that...
Qt Signal Slot Mapper
As sources I used among others:
http://developer.nokia.com/community/wiki/Mapping_signal_via_signalMapper
http://www.java2s.com/Code/Cpp/Qt/QSignalMapper.htm
Qt Slot Map
And this:
http://qt-project.org/doc/qt-4.8/qsignalmapper.html#setMapping
Which has the best explanation but still the lines I mentioned are unclear...