Hi,
Sorry for my English, I'm French...
I've got a class, like this
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;
};
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};
CMyLabel(QWidget *parent = 0);
EDataType getDataType(void) { return _dataType; }
void setDataType(EDataType dataType) { _dataType=dataType; }
private:
EDataType _dataType;
};
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:
{
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;
};
class CFoo : public QObject
{
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:
CMyLabel(QWidget *parent = 0);
CFoo::EDataType getDataType(void) { return _dataType; }
void setDataType(CFoo::EDataType dataType) { _dataType=dataType; }
private:
CFoo::EDataType _dataType;
};
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
Bookmarks