[Qt-interest] signals and slots....revisited...
Bo Thorsen
bo at fioniasoftware.dk
Mon Mar 14 08:10:52 CET 2011
Hi Sarvesh,
Den 13-03-2011 19:00, sarvesh saran skrev:
> I have been a Qt programmer for quite some time now and i understand
> most of the general features of Qt. I am still confused about how
> signals and slots work...
>
> this is what i know (correct me if i am wrong)
>
> 1. slots are like ordinary member functions.however they can be
> called via signals irrespective of their access specifier.
Yes. A slot is just a method.
> 2. emit is a macro that expands to nothing.
Correct. Your code would work without "emit" in front of signals, but
it's useful for Qt programmers to communicate that this is a signal
emit, so you have no way of knowing how long time it will take.
> 3. when you write emit mysignal() you are just calling a function
> called mysignal which has been implemented in the generated moc file.
Correct.
> 4. for every object (instantiated from a class containing Q_OBJECT
> macro and inheriting QObject) an addition meta object is
> instantiated ?
Only if your QObject subclass also have the Q_OBJECT macro.
class X : public QObject { ... }
If you don't have Q_OBJECT in the ... there is no additional meta object.
> 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.
> 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.
> 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.
> 8. while connecting, only the arguments of the slot is
> checked...surplus arguments are discarded.
Correct. You can have fewer arguments on the slots than there are on the
signals, and the generated moc code will just disregard those. But you
can't have more arguments on the slots than there are on the signals.
> 9. SIGNAL and SLOT are macros......not sure what their purpose is....
They generate the string from the slot/signal signature.
> i tried to look into the generated moc file but things are still
> murky..any help will be greatly appreciated.
I hope this helps :)
Bo Thorsen,
Fionia Software.
--
Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
More information about the Qt-interest-old
mailing list