Hi All
I've a doubt.
If we wants to define a slot then we've to use Q_OBJECT macro in my private part.
I need to know what Q_OBJECT do internally?
thank you all.
Hi All
I've a doubt.
If we wants to define a slot then we've to use Q_OBJECT macro in my private part.
I need to know what Q_OBJECT do internally?
thank you all.
Cheers,
Phillip
--- Please post the solution you got to solve your problem. It may help others.
did you read this?
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
Cheers,
Phillip
--- Please post the solution you got to solve your problem. It may help others.
Q_OBJECT is Qt's way to declare that a particular class's object wants to do some object communication. what a Q_OBJECT entry in a class does is that it tells the compiler to create moc files for that particular class which will have desired entries for signals and slots and other metatype information. If you are more curious to know about it, u should see qobjectdefs.h in Qt folder. Here is how Q_OBJECT is defined:
Qt Code:
/* tmake ignore Q_OBJECT */ #define Q_OBJECT \ public: \ Q_OBJECT_CHECK \ virtual void *qt_metacast(const char *); \ QT_TR_FUNCTIONS \ private: /* tmake ignore Q_OBJECT */ #define Q_OBJECT_FAKE Q_OBJECT /* tmake ignore Q_GADGET */ #define Q_GADGET \ public: \ private: #else // Q_MOC_RUN #define slots slots #define signals signals #define Q_SLOTS Q_SLOTS #define Q_SIGNALS Q_SIGNALSTo copy to clipboard, switch view to plain text mode
also another thing ...
c++ compiler will compile SIGNAL and SLOT as a string and not as a function .. Q_OBJECT's moc only does the magic of linking unrelated two objects ... for that only we get warning at run time of the qt application ... also to use qt resources , designer plugins, converting design.ui to ui_design.h ....etc , without Q_OBJECT nothing is possible ..
signal -slot connection are established in run time and signal and slot signatures are jusit string , Q_OBJECT::connect() will connect this two things ...
Last edited by wagmare; 26th March 2009 at 06:04.
no, SIGNAL and SLOT are not compiled as string at all..they are actually just internally treated as "protected"..when u include QObject, it internally includes qobjectdefs.h which has all the definitions of SIGNALS, SLOTS, Q_OBJECT, Q_SIGNALS, Q_SLOTS, what other functions are included in the moc files..everything
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
thanks ... why i am saying that SIGNAL and SLOT were considered as string is ..
what an expert told to me when i ask her
"why the connect is not showing error in compiling but only in run time in console ..?"
the reply she gave ..
"signal-slot connection are established at run-time , not at compiler time"
"Signal-Slot signatures are just strings for compiler thus no error it showing"
"QObject::Connect() will output a detailed warning when a connection failed"
this is the reply ... so only i suggest this to the latter post ...
well, its true that signal slot connection is established at run-time and yes, it will output a warning if connection fails..but its not just string but a "protected" access specifier..maybe she says its a string cuz its actually #define'd
Have you tried manually calling a slot as a function or retrieving its address? I assure you it works. Slots (and signals too) are regular functions, just with some extra treatment from moc.
Actually it does much more. Open a file generated by moc and see for yourself.Q_OBJECT's moc only does the magic of linking unrelated two objects
That's not true. You don't need Q_OBJECT to use Qt resources and you don't need the macro to "convert design.ui to ui_design.h" (nor to use it).... for that only we get warning at run time of the qt application ... also to use qt resources , designer plugins, converting design.ui to ui_design.h ....etc , without Q_OBJECT nothing is possible ..
Yes, this is true with one exception. They are not "just" strings, they are regular methods as well. The slot method is implemented by the programmer and the signal method is implemented by moc.signal -slot connection are established in run time and signal and slot signatures are jusit string
No, that's not true. Signals are treated as protected. Slots are treated based on how you defined them - if you defined them as private, they are private when called as a function and public when defined as public. The situation changes when you perform a connection - a slot called as a slot is always public, regardless of the section it was declared in.
Signatures are strings, that's correct. Moreover a signal signature is prepended with "1" and a slot signature is prepended with "2" so that you can't connect a slot to a slot. But that doesn't change the fact both the slots and the signals are regular methods of the class they are declared in.
talk2amulya (26th March 2009)
Bookmarks