PDA

View Full Version : error: invalid use of incomplete type 'struct QMetaEnum'



dyngoman
12th March 2010, 09:47
Hello,
I am new to Qt and C++ and just migrating from C# and .Net framework witch left me with a bitter taste in programming.
I am trying to get familiar with Qt development and came across this problem while trying to get strings from enum values.
I have used this link as a reference:
http://labs.trolltech.com/blogs/2008/10/09/coding-tip-pretty-printing-enum-values/
and used the ENUM_NAME macro defined therea as follow


QString strTag = ENUM_NAME(Cat,Cat::CatType,this->m_catType);

where Cat is the a class that inherits QObject and has the Q_OBJECT macro inside, and CatType is and enumeration

enum CatType{MAIDANEZA,CHARTREUX,PERSIAN}; parsed with the Q_ENUMS macro.

I get the following error:
cat.cpp:14:error: invalid use of incomplete type 'struct QMetaEnum'
qobjectdefs.h:240: error: forward declaration of 'struct QMetaEnum'

What could be the problem?

high_flyer
12th March 2010, 10:29
can you post your header file, including the includes?

dyngoman
12th March 2010, 11:02
#ifndef CAT_H
#define CAT_H

#include <QObject>

#define ENUM_NAME(o,e,v) (o::staticMetaObject.enumerator(o::staticMetaObjec t.indexOfEnumerator(#e)).valueToKey((v)))

class Cat:public QObject
{
Q_OBJECT
Q_ENUMS(CatType)

public:
enum CatType{MAIDANEZA,CHARTREUX,PERSIAN};

explicit Cat(QString name,CatType type,QObject *parent = 0):QObject(parent),Name(name),Kind(type){};

CatType Kind;
QString Name;
QString GetTag()
{
qDebug()<<QString("THIS IS A CAT TAG");
QString strTag = this->Name;
strTag += ENUM_NAME(Cat,Cat::CatType,this->Kind);
return strTag;
};

};

#endif // CAT_H

high_flyer
12th March 2010, 13:38
hmm, what happens if you add #include <QMetaEnum>?