Qt-interest Archive, April 2007
meta object system
Message 1 in thread
Hi all,
i am trying to gain a deeper understanding of Qt's Meta Object System,
and have been developing some test programs.. i have 2 questions..
help on any would be greatly appreciated
(1)
Firstly, just a quick question: is there no longer Qt's
QMetaObject::signalNames() method? Was this just a Qt 3 thing?
(2)
I also have another quick question: i was trying to find the methods
declared in a QObject subclass, so i defined the below test class:
class SillyClass : public QObject
{
Q_OBJECT
public:
SillyClass();
void normalMethod();
signals:
void signalOne();
void signalTwo();
public slots:
void slotOne();
void slotTwo();
}
i use the following code to test:
QMetaObject mo = SillyClass::staticMetaObject;
for ( int i = 0; i < mo.methodCount(); i++ )7-+3
{
QMetaMethod mm = mo.method(i);
cout << mo.className() << "::" << mm.signature() << endl;
}
i would have expected to see the inherited methods (from QObject), and
the normalMethod(), 2 signals and 2 slots i declared above... but i
only get the 2 slots, 2 signals and 4 other methods (
destroyed(QObject*), destroyed(), deleteLater() and
_q_registerTimers(void*) ) ...
why do i not get "normalMethod()" and other signals/slots declared in QObject?
and what are these other 4 methods? there's a lot more methods in
QObject! where are they?
thank you for your time.
regards,
nasser
--
[ signature omitted ]
Message 2 in thread
On Monday 16 April 2007 03:28, Nasser wrote:
> (1)
> Firstly, just a quick question: is there no longer Qt's
> QMetaObject::signalNames() method? Was this just a Qt 3 thing?
Yes :)
> (2)
> I also have another quick question: i was trying to find the methods
> declared in a QObject subclass, so i defined the below test class:
>
> class SillyClass : public QObject
> {
> Q_OBJECT
> public:
> SillyClass();
> void normalMethod();
> signals:
> void signalOne();
> void signalTwo();
> public slots:
> void slotOne();
> void slotTwo();
> }
>
> i use the following code to test:
[snip]
> i would have expected to see the inherited methods (from QObject), and
> the normalMethod(), 2 signals and 2 slots i declared above... but i
> only get the 2 slots, 2 signals and 4 other methods (destroyed(QObject*),
> destroyed(), deleteLater() and _q_registerTimers(void*) ) ...
>
> why do i not get "normalMethod()" and other signals/slots declared in
> QObject?
Because moc only understands methods that are declared as slots or signals, it
ignores normal member methods.
> and what are these other 4 methods? there's a lot more methods in
> QObject! where are they?
QObject::deleteLater() is a slot, so you see it.
QObject::destroyed(QObject * = 0) is a signal with a default argument, so
moc "overloads" it and turns it into 2 signals: QObject::destroyed() and
QObject::destroyed(QObject *). The last one is an private slot (declared by
Q_PRIVATE_SLOT(void _q_registerTimers(void *)) in qobject.h), which is used
by QObject::moveToThread(). You will encounter other private slots in Qt,
which are always prefixed with _q_.
--
[ signature omitted ]
Message 3 in thread
cool, thank you very much for clearing that for me..
so, there is no way to get the other methods declared (like Java's
reflection).. ?
because, i would like to invoke normal methods... however, i cannot do
that since their index is always returning -1 when i use
indexOfMethod().. so is there an alternative not going through MOC?
i would like to invoke a normal method using
QMetaObject::invokeMethod(...)... i can only do this if the method is
declared as a slot? (in order for it's index to be found)
.. i might have to implement something myself.. i'm playing around
with the "dynamic slots and signals" example from Qt Quarterly... got
a feeling that ideas will spark from there! :-)
thanks again!
nasser
On 4/16/07, Bradley T Hughes <bhughes@xxxxxxxxxxxxx> wrote:
> On Monday 16 April 2007 03:28, Nasser wrote:
> > (1)
> > Firstly, just a quick question: is there no longer Qt's
> > QMetaObject::signalNames() method? Was this just a Qt 3 thing?
>
> Yes :)
>
> > (2)
> > I also have another quick question: i was trying to find the methods
> > declared in a QObject subclass, so i defined the below test class:
> >
> > class SillyClass : public QObject
> > {
> > Q_OBJECT
> > public:
> > SillyClass();
> > void normalMethod();
> > signals:
> > void signalOne();
> > void signalTwo();
> > public slots:
> > void slotOne();
> > void slotTwo();
> > }
> >
> > i use the following code to test:
> [snip]
> > i would have expected to see the inherited methods (from QObject), and
> > the normalMethod(), 2 signals and 2 slots i declared above... but i
> > only get the 2 slots, 2 signals and 4 other methods (destroyed(QObject*),
> > destroyed(), deleteLater() and _q_registerTimers(void*) ) ...
> >
> > why do i not get "normalMethod()" and other signals/slots declared in
> > QObject?
>
> Because moc only understands methods that are declared as slots or signals, it
> ignores normal member methods.
>
> > and what are these other 4 methods? there's a lot more methods in
> > QObject! where are they?
>
> QObject::deleteLater() is a slot, so you see it.
> QObject::destroyed(QObject * = 0) is a signal with a default argument, so
> moc "overloads" it and turns it into 2 signals: QObject::destroyed() and
> QObject::destroyed(QObject *). The last one is an private slot (declared by
> Q_PRIVATE_SLOT(void _q_registerTimers(void *)) in qobject.h), which is used
> by QObject::moveToThread(). You will encounter other private slots in Qt,
> which are always prefixed with _q_.
>
> --
> Bradley T. Hughes - bhughes at trolltech.com
> Trolltech ASA - Sandakervn. 116, P.O. Box 4332 Nydalen, 0402 Oslo, Norway
>
--
[ signature omitted ]
Message 4 in thread
Hi,
> so, there is no way to get the other methods declared (like Java's
> reflection).. ?
Since C++ does not support reflection, it cannot be done using plain C++ classes.
> [...]
> .. i might have to implement something myself.. i'm playing around
> with the "dynamic slots and signals" example from Qt Quarterly... got
> a feeling that ideas will spark from there! :-)
Why not declare the methods you want to access using invokeMethod() as slots
and also use properties?
Otherwise you might end rewriting something to moc.
You may also try some object RPC (Remote Procedure Calling) protocol such as
SOAP, XML-RPC, Corba, DCOM, Ice. They usually involve some pre-procesing just
like moc and usually do offer introspection. Since these protocols also offer
RPC, moc is probably ligther, so it may suit your immediate needs better.
--
[ signature omitted ]
Message 5 in thread
i think for now, using slots and invokeMethod() should be fine.. will
definitely keep the other suggestions in mind! thanks for your help
:-)
cheers,
nasser
On 4/17/07, Dimitri <dimitri@xxxxxxxxxxxxx> wrote:
> Hi,
>
> > so, there is no way to get the other methods declared (like Java's
> > reflection).. ?
>
> Since C++ does not support reflection, it cannot be done using plain C++ classes.
>
> > [...]
> > .. i might have to implement something myself.. i'm playing around
> > with the "dynamic slots and signals" example from Qt Quarterly... got
> > a feeling that ideas will spark from there! :-)
>
> Why not declare the methods you want to access using invokeMethod() as slots
> and also use properties?
>
> Otherwise you might end rewriting something to moc.
>
> You may also try some object RPC (Remote Procedure Calling) protocol such as
> SOAP, XML-RPC, Corba, DCOM, Ice. They usually involve some pre-procesing just
> like moc and usually do offer introspection. Since these protocols also offer
> RPC, moc is probably ligther, so it may suit your immediate needs better.
>
> --
> Dimitri
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 6 in thread
On Monday 16 April 2007 23:58, Nasser wrote:
> cool, thank you very much for clearing that for me..
>
> so, there is no way to get the other methods declared (like Java's
> reflection).. ?
>
> because, i would like to invoke normal methods... however, i cannot do
> that since their index is always returning -1 when i use
> indexOfMethod().. so is there an alternative not going through MOC?
>
> i would like to invoke a normal method using
> QMetaObject::invokeMethod(...)... i can only do this if the method is
> declared as a slot? (in order for it's index to be found)
Well, there is this nice (but undocumented) feature called Q_INVOKABLE, which
you can put in front of every method that you want to invoke (but don't want
to make a slot). For example:
class Room : public QObject
{
Q_OBJECT
public:
...
Q_INVOKABLE void normalMethod();
public slots:
...
signals:
...
};
> .. i might have to implement something myself.. i'm playing around
> with the "dynamic slots and signals" example from Qt Quarterly... got
> a feeling that ideas will spark from there! :-)
;)
--
[ signature omitted ]
Message 7 in thread
> Well, there is this nice (but undocumented) feature called Q_INVOKABLE, which
> you can put in front of every method that you want to invoke (but don't want
> to make a slot). For example:
that worked awesome! thanks...
however i tried searching where it was defined so i can better
understand what's going on... but all i could find was in
"qobjectdefs.h" it was defined as
#define Q_INVOKABLE Q_INVOKABLE
but that's not really what did the magic right? .. where else was it
defined? .. does Q_INVOKABLE pretty much make the method a slot? ..
because i notice that the method is now part of
qt_meta_stringdata_MyClass and a switch-statement option in
qt_metacall(...)
thanks again!
nasser
On 4/17/07, Bradley T Hughes <bhughes@xxxxxxxxxxxxx> wrote:
> On Monday 16 April 2007 23:58, Nasser wrote:
> > cool, thank you very much for clearing that for me..
> >
> > so, there is no way to get the other methods declared (like Java's
> > reflection).. ?
> >
> > because, i would like to invoke normal methods... however, i cannot do
> > that since their index is always returning -1 when i use
> > indexOfMethod().. so is there an alternative not going through MOC?
> >
> > i would like to invoke a normal method using
> > QMetaObject::invokeMethod(...)... i can only do this if the method is
> > declared as a slot? (in order for it's index to be found)
>
> Well, there is this nice (but undocumented) feature called Q_INVOKABLE, which
> you can put in front of every method that you want to invoke (but don't want
> to make a slot). For example:
>
> class Room : public QObject
> {
> Q_OBJECT
>
> public:
> ...
>
> Q_INVOKABLE void normalMethod();
>
> public slots:
> ...
> signals:
> ...
> };
>
> > .. i might have to implement something myself.. i'm playing around
> > with the "dynamic slots and signals" example from Qt Quarterly... got
> > a feeling that ideas will spark from there! :-)
>
> ;)
>
> --
> Bradley T. Hughes - bhughes at trolltech.com
> Trolltech ASA - Sandakervn. 116, P.O. Box 4332 Nydalen, 0402 Oslo, Norway
>
--
[ signature omitted ]
Message 8 in thread
Hi,
> however i tried searching where it was defined so i can better
> understand what's going on... but all i could find was in
> "qobjectdefs.h" it was defined as
>
> #define Q_INVOKABLE Q_INVOKABLE
>
> but that's not really what did the magic right? .. where else was it
> defined? .. does Q_INVOKABLE pretty much make the method a slot? ..
> because i notice that the method is now part of
> qt_meta_stringdata_MyClass and a switch-statement option in
> qt_metacall(...)
The magic is done by moc. Since reflection is not part of C++, it can only be
achieved with help from a pre-processor (or by manually coding the reflection
code).
Q_INVOKABLE could be a good addition to the (official) Qt API...
--
[ signature omitted ]