Im trying to do the same thing that trolltech does in qnamespace.h. When moc runs it's an object but when the compiler runs it's a namespace. I think this will enable me to use staticMetaObject and QMetaEnum to get my enums as strings also.
I am aware that i can do this in my class if i inherit QObject, but i want my enums in a namespace. Just like Qt
Here's what im trying:
Qt Code:
#include <QtCore/QObject> #ifndef Q_MOC_RUN namespace #else class ICOMM_EXPORT #endif iComm /* #if defined(Q_MOC_RUN) :public QObject #endif */ { #if defined(Q_MOC_RUN) Q_OBJECT Q_ENUMS(PackageType) #endif #if defined(Q_MOC_RUN) public: #endif enum PackageType{ Unknown, Ping, Pong, SendUserInfo, UserInfo, SendAgentInfo, AgentInfo, AddUser, UpdateStatus, SendStatusInfo, StatusInfo, SendOnlineStatus, OnlineStatus, IM }; } #ifdef Q_MOC_RUN ; #endifTo copy to clipboard, switch view to plain text mode
But moc complains:
src/iNamespace.hh:17: Error: Class contains Q_OBJECT macro but does not inherit from QObject
If i make it inherit QObject g++ complains:
src/.moc/moc_iNamespace.cpp:61: error: ‘iComm::staticMetaObject’ should have been declared inside ‘iComm’
src/.moc/moc_iNamespace.cpp:66: error: ‘const QMetaObject* iComm::metaObject()’ should have been declared inside ‘iComm’
src/.moc/moc_iNamespace.cpp:66: error: non-member function ‘const QMetaObject* iComm::metaObject()’ cannot have cv-qualifier
src/.moc/moc_iNamespace.cpp:71: error: ‘void* iComm::qt_metacast(const char*)’ should have been declared inside ‘iComm’
src/.moc/moc_iNamespace.cpp: In function ‘void* iComm::qt_metacast(const char*)’:
src/.moc/moc_iNamespace.cpp:75: error: expected type-specifier before ‘iComm’
src/.moc/moc_iNamespace.cpp:75: error: expected `>' before ‘iComm’
src/.moc/moc_iNamespace.cpp:75: error: expected `(' before ‘iComm’
src/.moc/moc_iNamespace.cpp:75: error: expected primary-expression before ‘*’ token
src/.moc/moc_iNamespace.cpp:75: error: expected primary-expression before ‘>’ token
src/.moc/moc_iNamespace.cpp:75: error: invalid use of ‘this’ in non-member function
src/.moc/moc_iNamespace.cpp:75: error: expected `)' before ‘;’ token
src/.moc/moc_iNamespace.cpp:76: error: cannot call member function ‘virtual void* QObject::qt_metacast(const char*)’ without object
src/.moc/moc_iNamespace.cpp: At global scope:
src/.moc/moc_iNamespace.cpp:79: error: ‘int iComm::qt_metacall(QMetaObject::Call, int, void**)’ should have been declared inside ‘iComm’
src/.moc/moc_iNamespace.cpp: In function ‘int iComm::qt_metacall(QMetaObject::Call, int, void**)’:
src/.moc/moc_iNamespace.cpp:81: error: cannot call member function ‘virtual int QObject::qt_metacall(QMetaObject::Call, int, void**)’ without object
make: *** [src/.obj/moc_iNamespace.o] Error 1
Bookmarks