[Qt-interest] getting inside the moc

Girish Ramakrishnan girish at forwardbias.in
Mon May 11 11:02:53 CEST 2009


Hi,

Luca Ferrari wrote:
> Hi all,
> I'm just curious to understand how the moc and signal/slot works in qt. So I 
> created a simple couple of classes with signals and slots and I'm having a 
> look at the moc produced files.
> As far as I can understand, the idea is to implement each signal with a 
> function that wraps the arguments and invokes activate on the target object. 
> In both signaller and receiver the qt_metacall implementation dispatches 
> signals to the right slot, choosing the signal to issue depending on an 
> integer index and invoking the target method depending on the same index (on 
> the target class). So a signal is mapped as "signal function 2" and is 
> invoked, on the target the slot connected (let's say slot number 3) is 
> invoked.
> So a lot of work is done by qt_metacall, and QObject:connect stores the 
> matching between the two indexes.
> However, not all the details are clear to me.
> For instance, there is a string qt_meta_stringdata that contains a kind of 
> prototype of signals and slots and their parameter names. What is its purpose 
> and why it does not report duplicated values (e.g., duplicated variable 
> names)?

It is just an optimization for space. Strings inside qt_meta_stringadata
are not repeated.

> And how are the array of signal and slots associated? In the qt_meta_data 
> array there is something like:
> 
>  // signals: signature, parameters, type, tag, flags
>       22,    8,    7,    7, 0x05,
>       41,    7,    7,    7, 0x05,
>       73,   54,    7,    7, 0x05,
> 
> but how has to be read the above map?

The values index into the qt_meta_stringdata. So, for the first signal,
qt_meta_stringdata[22] will have the signature, [8] will have the
params, [7] the return value and so on. flags has to do with access
permissions and other flags :-)

> Is there any document about how the moc works and signals/slots are 
> implemented?
> 

Not that I am aware of, but it is not really that black-magic. Have a
look at src/tools/moc/. generator.cpp is very easy to read. And the code
in qobject.cpp will explain how the metadata is used.

Girish



More information about the Qt-interest-old mailing list