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

Thiago Macieira thiago at kde.org
Mon Mar 14 16:16:38 CET 2011


Em segunda-feira, 14 de março de 2011, às 08:10:52, Bo Thorsen escreveu:
> >    5. QT stores the names slots and signals of an object in its  meta
> >       object? in what format.....<name,function pointer> ?
> 
> Something like it, yes. But you don't need to know. Just use the SLOT 
> and SIGNAL macros to access them.

They are stored in the object, not in the meta-object. The "Meta" prefix, 
according to wikipedia, is used "to indicate a concept which is an abstraction 
from another concept, used to complete or add to the latter." (like "metadata" 
is information about the data)

The meta-object is information about the object. It's actually tied to the 
class, not to the object. So the meta-object describes the class, its signals 
and its slots.

Since the signal-slot connection is between two objects (instances of a class) 
and not between all instances of that class, it's stored in the object. It's 
stored in the private section of QObject.

> >    6. connections between objects are made at runtime...how?? not sure
> >       how and where a slot is searched for....
> 
> The SLOT and SIGNAL macros generates a string based on name, type (slot 
> or signal) and arguments. Then it does a string compare until it finds 
> the one it's looking for.

It's a glorified many-to-many callback mechanism. The simplest callback 
mechanism is to store a function pointer to the function you want called in 
the event something happens (that is, "a signal is emitted").

The next step is to have a list of functions instead, so you can have many 
listeners for this event.

After that, you add the possibility to have C++ member functions, then the 
information about the class (introspection, reflection, "meta-object", etc.).

> >    7. but the arguments in the connect call are matched at compile time?
> 
> No, it's all runtime. If you need compile time matching, boost signals 
> is the solution.

We have the same solution in Qt in a research branch, but the problem we have 
is that the C++ protection mechanism for members applies. Right now, "signals" 
expands to "protected", so you could only access the signals if you derive 
from the class in question.

There are also some other drawbacks caused by the fact that the connection is 
done directly to a function pointer or PMF, instead of via a virtual method 
call.

> >    9. SIGNAL and SLOT are macros......not sure what their purpose is....
> 
> They generate the string from the slot/signal signature.

If you write SIGNAL(foo), you get "2foo". That's all.

> > i tried to look into the generated moc file but things are still
> > murky..any help will be greatly appreciated.

The output of moc is the meta object itself (which one big string and an 
integer table) plus the functions in the class that return the meta object and 
the qt_metacall virtual, which is what dispatches the invocations of slots and 
signals.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110314/322d46c6/attachment.bin 


More information about the Qt-interest-old mailing list