Results 1 to 4 of 4

Thread: error: invalid use of incomplete type 'struct QMetaEnum'

  1. #1
    Join Date
    Feb 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default error: invalid use of incomplete type 'struct QMetaEnum'

    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...g-enum-values/
    and used the ENUM_NAME macro defined therea as follow

    Qt Code:
    1. QString strTag = ENUM_NAME(Cat,Cat::CatType,this->m_catType);
    To copy to clipboard, switch view to plain text mode 

    where Cat is the a class that inherits QObject and has the Q_OBJECT macro inside, and CatType is and enumeration
    Qt Code:
    1. enum CatType{MAIDANEZA,CHARTREUX,PERSIAN};
    To copy to clipboard, switch view to plain text mode 
    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: error: invalid use of incomplete type 'struct QMetaEnum'

    can you post your header file, including the includes?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error: invalid use of incomplete type 'struct QMetaEnum'

    Qt Code:
    1. #ifndef CAT_H
    2. #define CAT_H
    3.  
    4. #include <QObject>
    5.  
    6. #define ENUM_NAME(o,e,v) (o::staticMetaObject.enumerator(o::staticMetaObject.indexOfEnumerator(#e)).valueToKey((v)))
    7.  
    8. class Cat:public QObject
    9. {
    10. Q_OBJECT
    11. Q_ENUMS(CatType)
    12.  
    13. public:
    14. enum CatType{MAIDANEZA,CHARTREUX,PERSIAN};
    15.  
    16. explicit Cat(QString name,CatType type,QObject *parent = 0):QObject(parent),Name(name),Kind(type){};
    17.  
    18. CatType Kind;
    19. QString Name;
    20. QString GetTag()
    21. {
    22. qDebug()<<QString("THIS IS A CAT TAG");
    23. QString strTag = this->Name;
    24. strTag += ENUM_NAME(Cat,Cat::CatType,this->Kind);
    25. return strTag;
    26. };
    27.  
    28. };
    29.  
    30. #endif // CAT_H
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: error: invalid use of incomplete type 'struct QMetaEnum'

    hmm, what happens if you add #include <QMetaEnum>?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 9
    Last Post: 29th August 2010, 14:30
  2. Replies: 4
    Last Post: 12th October 2009, 19:36
  3. Replies: 1
    Last Post: 4th September 2008, 14:55
  4. Replies: 5
    Last Post: 28th September 2007, 10:23
  5. Replies: 3
    Last Post: 4th August 2006, 12:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.