Results 1 to 3 of 3

Thread: How to use custom enum in designer that be decladred in an other class

  1. #1
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to use custom enum in designer that be decladred in an other class

    Hi,

    Sorry for my English, I'm French...

    I've got a class, like this

    Qt Code:
    1. class QDESIGNER_WIDGET_EXPORT CMyLabel : public QLabel
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(EDataType dataType READ getDataType WRITE setDataType)
    5. Q_ENUMS(EDataType)
    6. public:
    7. enum EDataType {edtString=0, edtInt, edtDouble, edtDate};
    8.  
    9. CMyLabel(QWidget *parent = 0);
    10. EDataType getDataType(void) { return _dataType; }
    11. void setDataType(EDataType dataType) { _dataType=dataType; }
    12. private:
    13. EDataType _dataType;
    14. };
    To copy to clipboard, switch view to plain text mode 

    Which works very well in designer, the EDataType enum is visible in properties editor for property dataType.

    Because EDataType is used in other class, I want to declare EDataType outside the class, so, as stated in the doc
    If you want to register an enum that is declared in another class, the enum must be fully qualified with the name of the class defining it. In addition, the class defining the enum has to inherit QObject as well as declare the enum using Q_ENUMS().
    I do this:

    Qt Code:
    1. class CFoo : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. enum EDataType {edtString=0, edtInt, edtDouble, edtDate};
    6. };
    7.  
    8.  
    9. class QDESIGNER_WIDGET_EXPORT CMyLabel : public QLabel
    10. {
    11. Q_OBJECT
    12. Q_PROPERTY(CFoo::EDataType dataType READ getDataType WRITE setDataType)
    13. Q_ENUMS(CFoo::EDataType)
    14. public:
    15. CMyLabel(QWidget *parent = 0);
    16. CFoo::EDataType getDataType(void) { return _dataType; }
    17. void setDataType(CFoo::EDataType dataType) { _dataType=dataType; }
    18. private:
    19. CFoo::EDataType _dataType;
    20. };
    To copy to clipboard, switch view to plain text mode 

    It compile very well, but when I launch designer, I've got this error:

    And the EDataType enum is not visible in properties editor.
    QMetaProperty::read: Unable to handle unregistered datatype 'CFoo::EDataType' for property 'CMyLabel::dataType'

    How can i do this ?

    Thanks

    Corentin

  2. #2
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use custom enum in designer that be decladred in an other class

    Hi,

    I solved it alone, simply like this

    Qt Code:
    1. class CFoo : public QObject
    2. {
    3. Q_OBJECT
    4. Q_ENUMS(EDataType)
    5. public:
    6. enum EDataType {edtString=0, edtInt, edtDouble, edtDate};
    7. };
    8.  
    9.  
    10. class QDESIGNER_WIDGET_EXPORT CMyLabel : public QLabel
    11. {
    12. Q_OBJECT
    13. Q_PROPERTY(CFoo::EDataType dataType READ getDataType WRITE setDataType)
    14. Q_ENUMS(CFoo::EDataType)
    15. public:
    16. CMyLabel(QWidget *parent = 0);
    17. CFoo::EDataType getDataType(void) { return _dataType; }
    18. void setDataType(CFoo::EDataType dataType) { _dataType=dataType; }
    19. private:
    20. CFoo::EDataType _dataType;
    21. };
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use custom enum in designer that be decladred in an other class

    I think you don't need line #14 in your code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 7
    Last Post: 18th August 2011, 14:43
  2. QItemEditorFactory and custom enum types.
    By hickscorp in forum Qt Programming
    Replies: 4
    Last Post: 7th August 2011, 16:08
  3. show custom enum property in designer?
    By qlands in forum Qt Programming
    Replies: 0
    Last Post: 5th July 2011, 17:12
  4. static enum in a class
    By mickey in forum General Programming
    Replies: 3
    Last Post: 19th August 2008, 19:02
  5. Store an custom enum in QSettings
    By Lykurg in forum Qt Programming
    Replies: 1
    Last Post: 14th March 2007, 20:06

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
  •  
Qt is a trademark of The Qt Company.