I came across a declaration similar to this (names changed per NDA):
class Foo
{
int bar;
public:
explicit Foo (Fu *parent = NULL);
private:
void somefunc (String);
signals: // ??? what does this do ???
void windowClosed();
};
This is compiled successfully by g++ 4.4.7 (from about 2012). Additionally, vim recognizes it as a keyword similar to public
and private
by highlighting them in brown. (Dis)similiarly, vim uses green to highlight the keywords namespace
, class
, void
, int
, double
, float
, char
, unsigned
, etc.
The Stackoverflow code formatter does not highlight signals
above like it does public
and private
!
It has proved quite difficult to Google for this (lots of noise), but I haven't found anything mentioning it, not even on SO. I also looked in the enhancements section of the g++ documentation.
This codebase is large (23+ million lines), oldish (~1998), and has a distinct accent. For example, the same class definition has the class access private slots:
before two member functions. So it is possible there is some #define
obfuscation or trickery going on, but I can't find it using grep
. It is possible g++ has been altered, but its --version
output does not indicate modification.
In Qt, we have an alternative to the callback technique: We use signals and slots. A signal is emitted when a particular event occurs. Qt's widgets have many predefined signals, but we can always subclass widgets to add our own signals to them. A slot is a function that is called in response to a particular signal.
In Qt, we have an alternative to the callback technique: We use signals and slots. A signal is emitted when a particular event occurs. Qt's widgets have many predefined signals, but we can always subclass widgets to add our own signals to them. A slot is a function that is called in response to a particular signal.
disconnect(& myConnect);
A public slots section contains slots that anyone can connect signals to. This is very useful for component programming: you create objects that know nothing about each other, connect their signals and slots so that information is passed correctly, and, like a model railway, turn it on and leave it running.
It isn't a keyword, if you're using a framework such as Qt it adds up 'keywords' to the language to provide additional functionality that isn't part of the standard.
In Qt for example this code gets preproccessed by the MOC(Meta-Object Compiler), signals
is defined in qobjectdefs.h
as #define signals public
, the moc checks for this macro to add meta-code and provide the actual signal-slot functionality, the generated code is put into a file with a name such as 'moc_myClass.cpp'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With