Set Enum via setProperty



  • I need a setup Enum via setProperty

    Example class:

    @class A : public QObject{
    Q_PROPERTY(E_VALUE READ eValue WRITE setEValue )
    Q_OBJECT
    Q_ENUMS(E_VALUE)
    public:
    enum E_VALUE { Internal = 0, External };
    E_VALUE eValue() const;
    void setEValue( const E_VALUE &value );
    };

    Q_DECLARE_METATYPE(A::E_VALUE)@

    And for example i store it in QSettings, and then get it as QVariant

    @// settings is QSettings
    A * a = new A;
    a->setProperty(settings.value("E_VALUE"));@

    or my setter is not called at all.

    Can somebody point me, to what i missed ? Please, and thx.


  • Lifetime Qt Champion

    Hi,

    Is it a typo or are you missing a parameter to setProperty ?

    Did you check that settings.value() returns something valid ?



  • Hi,
    You are also missing the property name in your Q_PROPERTY declaration.
    This is the name you must specify in setProperty as SGaist mentioned.



  • O sorry setProperty exist and accept A::E_VALUE param. Just miss it, in example.

    Yes debugger show that returning type is int


  • Lifetime Qt Champion

    To properly load and save your custom metatype you also need to provide and register the corresponding QDataStream operators


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.