[Qt-interest] QMetaObject doesn't know about methods on QObject
Stephen Kelly
steveire at gmail.com
Fri Jan 9 16:33:13 CET 2009
Thiago Macieira wrote:
> On Friday 09 January 2009 12:28:31 Stephen Kelly wrote:
>> 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.
Great thanks. I think that's exactly what I need.
I also discovered that I need to use Q_ENUMS() with the enum names separated by spaces to make the enums available.
class MyClass : public QObject
{
Q_OBJECT
public:
Q_ENUMS(MyEnum MyOtherEnum)
enum MyEnum {
One,
Two
};
enum MyOtherEnum {
First,
Second
};
MyClass();
Q_INVOKABLE void setSomething(int i =0);
Q_INVOKABLE int getSomething() const;
};
********
qDebug() << "enums:";
for ( int i = 0; i < mObj->enumeratorCount(); ++i )
{
QMetaEnum me = mObj->enumerator(i);
qDebug() << "enum name" << me.name();
for ( int j=0; j < me.keyCount(); ++j )
{
qDebug() << me.key(j) << "=" << me.value(j);
}
}
*********
enums:
enum name MyEnum
One = 0
Two = 1
enum name MyOtherEnum
First = 0
Second = 1
Thanks for the help,
Steve
>
> 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.
More information about the Qt-interest-old
mailing list