[Qt-interest] QMetaObject doesn't know about methods on QObject
Thiago Macieira
thiago.macieira at trolltech.com
Fri Jan 9 13:44:12 CET 2009
On Friday 09 January 2009 12:28:31 Stephen Kelly wrote:
> Hi,
>
> Consider this:
>
> QObject *obj= new QObject();
> const QMetaObject *mObj = obj->metaObject();
>
> for (int i = 0; i < mObj->methodCount(); ++i)
> {
> QMetaMethod mm = mObj->method(i);
>
> qDebug() << (mm.methodType() == QMetaMethod::Signal) <<
> (mm.methodType() == QMetaMethod::Slot) << (mm.methodType() ==
> QMetaMethod::Method) << mm.signature() << mm.parameterNames() <<
> mm.parameterTypes(); }
>
> I expect it to output a line for each method in QObject, but it actually
> only prints signals and slots despite the docs of QMetaObject implying
> otherwise: http://doc.trolltech.com/4.4/qmetaobject.html#methodCount
>
> > These include signals and slots as well as normal member functions
>
> I also can't seem to iterate over the enums in a class when introspecting
> QThread.
>
> Anyone know what's going on here? Am I missing something important?
Looks like the documentation is a bit misleading.
The meta object contains normal methods but only as long as you've asked moc
to read them. You have to prefix each method declaration in your class that you
intend to be extracted by moc with Q_INVOKABLE.
i.e.:
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass();
Q_INVOKABLE void setSomething(int);
Q_INVOKABLE int getSomething() const;
Q_SCRIPTABLE void scriptableCall();
Q_SLOT void aSlot();
Q_SIGNAL void aSignal();
};
Q_SCRIPTABLE is like Q_INVOKABLE but sets an extra flag. It's meant to be used
with QtScript and QtDBus. It can also be set on slots and signals.
The Q_SLOT and Q_SIGNAL (note singular) macros are meant to complement the
feature set.
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Software Engineer - Nokia, Qt Software
Qt Software is hiring - ask me
Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090109/994da92f/attachment.bin
More information about the Qt-interest-old
mailing list