Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Set Enum via setProperty

Set Enum via setProperty

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxvanceffer
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • U Offline
        U Offline
        unai_i
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxvanceffer
          wrote on last edited by
          #4

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

          Yes debugger show that returning type is int

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved