[Qt-interest] signals and slots....revisited...
sarvesh saran
aquarian.thunder at gmail.com
Mon Mar 14 10:43:32 CET 2011
Hi,
which brings up this question again.....how is the connection made at run
time?
thanks,
Sarvesh
On Mon, Mar 14, 2011 at 2:14 PM, Bo Thorsen <bo at fioniasoftware.dk> wrote:
> Den 14-03-2011 09:22, sarvesh saran skrev:
>
> Hi Bo,
>>
>> thank you for your answer. There was one question that is still
>> unanswered...
>>
>> 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./
>> /
>> /
>> I would like to know...at least at a higher abstraction. The SLOT and
>> SIGNAL macros would generate a string representation of the signal and
>> the slot containing the name, arguments etc (kind like a mangled C++
>> method name?). These names are then looked up (where?) and the
>> appropriate slots are called ( i guess through the meta
>> object?..qt_metacall).
>>
>
> I did this:
>
> QLOG_DEBUG() << "Slot:" << SLOT(onFirmwareUpdateAvailable(QString)) <<
> "signal:" << SIGNAL(customContextMenuRequested(QPoint));
>
> And got this output:
>
> Slot: 1onFirmwareUpdateAvailable(QString)
> signal: 2customContextMenuRequested(QPoint)
>
> These really are just strings with a 1 for a slot and 2 for a signal.
> connect() compares these to the lists in the generated moc code and finds
> the proper signal or slot.
>
>
> I want this info for a variety of reasons...i was under the belief that
>> signals and slots involve function pointers until some one very recently
>> contradicted this...so i would like some clarification as to how the
>> signals/slots are mapped,looked up and called?
>>
>
> You need to read the generated moc code.
>
> On Mon, Mar 14, 2011 at 12:40 PM, Bo Thorsen <bo at fioniasoftware.dk
>> <mailto:bo at fioniasoftware.dk>> wrote:
>>
>> 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
>>
>>
>>
>
> Bo Thorsen,
> Fionia Software.
>
> --
>
> Expert Qt and C++ developer for hire
> Contact me if you need expert Qt help
> http://www.fioniasoftware.dk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110314/f42a12b3/attachment.html
More information about the Qt-interest-old
mailing list