[Qt-interest] QObject::enumeratorCount() returns 0

Jesús Fernández jsfdez at gmail.com
Wed Dec 17 16:21:00 CET 2008


I have forgotten the Q_ENUMS(Key) :(

On Wed, Dec 17, 2008 at 2:42 PM, Jesús Fernández <jsfdez at gmail.com> wrote:
> Hi,
>
> I have this classes
>
> HEADERS:
>
> #include <QSettings>
>
> class QString;
>
> // NOTE: The first child enum must be named Key
>
> class Settings : public QSettings {
>        Q_OBJECT
>
> public:
>        Settings(QObject *parent=0);
>        ~Settings();
>
>        virtual QString group() const=0;
>
>        QString keyName(int key) const;
>        void setValue(int key, const QVariant &value);
>        QVariant value(int key, const QVariant &defaultValue=QVariant());
> protected:
>        enum {
>                InvalidKey=-1,
>                FirstKey=0
>        };
>
>        void init();
> };
>
> class DatabaseSettings:public Settings {
>        Q_OBJECT
>
> public:
>        enum Key {
>                ConnectionString=FirstKey
>        };
>
>        QString group() const;
>        QVariant value(Key key);
> };
>
>
> -----------------------------
>
>
> SOURCES:
>
> QString Settings::keyName(int key) const
> {
>        const QMetaObject *meta=metaObject();
>
>        qDebug()<<meta->enumeratorCount();                    // <---- This
shows 0
>        int enumerator=meta->indexOfEnumerator("Key");
>        QMetaEnum metaEnum=meta->enumerator(enumerator);
>        QString name(metaEnum.key(key));
>
>        Q_ASSERT(!name.isEmpty());
>        return name;
> }
>
>
> The problem is that in this portion of code the meta object always
> returns 0 and I can't get the enumerator, anyone sees the problem?
>
> Thanks
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081217/7401a57b/attachment.html 


More information about the Qt-interest-old mailing list