[Qt-interest] signals and slots....revisited...

Jason Melbye jason.melbye at gmail.com
Tue Mar 15 05:53:58 CET 2011


On Mon, Mar 14, 2011 at 12:11 PM, sarvesh saran
<aquarian.thunder at gmail.com> wrote:
> It amazes me how someone can use Qt for longer time and not understand
> signals/slots...
> it amazes me too.....quite absurd and downright shocking i'd say :-)
> I guess i am asking the wrong questions...i was more interested in  how a
> slot is found a.k.a looked up at run time...not how they *work* or how they
> are *used* or their *syntax*...the documentation is as i (and every body
> else ) pointed out earlier, pretty clear about this.
> -sarvesh

I'm pretty new to all of this, please do correct me if I'm wrong.  I
wanted to give this a stab since I've been trying to work through this
myself.

>From what I can tell, information about your signals and slots is
stored in two arrays in your moc_ files, qt_meta_meta_data_MyObject[]
and qt_meta_stringdata_MyObject[]

For former has numerical data about your signals and slots, mostly
indices into the latter.  The latter is string data with the name of
your object, argument names and types of your signals and slots, and
the names of your signals and slots.

The moc assigns integer values to your signals and slots as it parses
your files.  Those values are offsets into the qt_meta_data_myObject[]
array.  There is a "header" at the beginning of the array of known,
fixed size it looks like, followed by data for every signal and slot.
You can find specific information for a signal or slot with index
value i at qt_meta_data_MyObject[fixed_header_length + (i * length of
a signal/slot record)]

This is all laid out at compile time (or pre-process time really).

At run time, when you call connect, I think those macros actually
replace the text of the signal or slot name with an index.  Behind the
scenes, the meta system is keeping a list of every slot that is
associated with each signal.  If I call connect(object1, 1, object2,
2), then the slot specified by the index 2 for object2 is appended to
the list of slots to call in when the signal specified by the index 1
for object1.

The firing of these slots happens through a call to QMetaObject::activate();

The translation of the integer indicies to actual signals or slots
happens in your moc file(s), in the generated function
MyObject::qt_metacall().  To respond to an earlier question, you
should be able to see that the function is directly called.  This is
not done through function pointers.

Jason



More information about the Qt-interest-old mailing list