A signal is a function which is called as the result of some kind of event or action. For example, the click of a push button. A slot is a function which you may connect to a signal, so that whenever the signal is actioned, the slot function is called.
This is all well, good and easy to implement in C++ as part of Qt, because there are build tools which are there to generate glue framework code for you.
But of course, having to run extra utilities when trying to build your BlitzMax application wouldn't be very useful. One should simply be able to knock some code together and run it.
After mulling over this obvious problem for a while, I came up with what I think is quite a clever system which works in a functionally similar way to the C++ code....
On the low-level side, every C++ signal needs to be connected to a BlitzMax utility function.
On the BlitzMax side, the base QObject holds a list of all connections to any of its own signals. Instead of connecting a callback function pointer (like we would with wxMax), we rather pass in the name of the method to connect the signal to. Using reflection we can map the method name to the actual method which we will later call.
When the signal is actioned, every method (slot) which has connected to the signal is called in turn.
It all works seamlessly :-)
The sliders example is a very good demonstration of the system in action, and even shows the ability to create your own BlitzMax-based signal method.
Although we aren't really using the Qt signal/slot framework properly - since the real signal and slot connections are hard-coded into the modules - it functions in exactly the same way, which is really all we need to worry about ;-)
No comments:
Post a Comment