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
Code:
class QDESIGNER_WIDGET_EXPORT CMyLabel
: public QLabel{
Q_OBJECT
Q_PROPERTY(EDataType dataType READ getDataType WRITE setDataType)
Q_ENUMS(EDataType)
public:
enum EDataType {edtString=0, edtInt, edtDouble, edtDate};
EDataType getDataType(void) { return _dataType; }
void setDataType(EDataType dataType) { _dataType=dataType; }
private:
EDataType _dataType;
};
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
Quote:
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:
Code:
{
Q_OBJECT
public:
enum EDataType {edtString=0, edtInt, edtDouble, edtDate};
};
class QDESIGNER_WIDGET_EXPORT CMyLabel
: public QLabel{
Q_OBJECT
Q_PROPERTY(CFoo::EDataType dataType READ getDataType WRITE setDataType)
Q_ENUMS(CFoo::EDataType)
public:
CFoo::EDataType getDataType(void) { return _dataType; }
void setDataType(CFoo::EDataType dataType) { _dataType=dataType; }
private:
CFoo::EDataType _dataType;
};
It compile very well, but when I launch designer, I've got this error:
And the EDataType enum is not visible in properties editor.
Quote:
QMetaProperty::read: Unable to handle unregistered datatype 'CFoo::EDataType' for property 'CMyLabel::dataType'
How can i do this ?
Thanks
Corentin
Re: How to use custom enum in designer that be decladred in an other class
Hi,
I solved it alone, simply like this
Code:
{
Q_OBJECT
Q_ENUMS(EDataType)
public:
enum EDataType {edtString=0, edtInt, edtDouble, edtDate};
};
class QDESIGNER_WIDGET_EXPORT CMyLabel
: public QLabel{
Q_OBJECT
Q_PROPERTY(CFoo::EDataType dataType READ getDataType WRITE setDataType)
Q_ENUMS(CFoo::EDataType)
public:
CFoo::EDataType getDataType(void) { return _dataType; }
void setDataType(CFoo::EDataType dataType) { _dataType=dataType; }
private:
CFoo::EDataType _dataType;
};
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.