Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED] Q_PROPERTY only working for boolean setters/getters
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Q_PROPERTY only working for boolean setters/getters

Scheduled Pinned Locked Moved C++ Gurus
4 Posts 2 Posters 1.8k 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.
  • A Offline
    A Offline
    ASxa86
    wrote on last edited by
    #1

    I'm attempting to add a Q_PROPERTY for time.

    @
    Q_PROPERTY(int64_t time READ getTime WRITE setTIME)

    void setTime(const int64_t x);
    int64_t getTime() const;
    @

    I can't get this to show up in QtDesigner for my custom widget.

    In fact, I can't get this to work for any data type besides boolean.

    @
    Q_PROPERTY(bool value READ getValue WRITE setValue)

    void setValue(const bool x);
    bool getValue() const;
    @

    This works just fine.

    Am I missing something? I've read over the documentation and have not been able to come up with a solution.

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

      Hi,

      When using special types, you must make it known to Qt using Q_DECLARE_METATYPE and qRegisterMetaType. It's explained with more details in the "Property System" chapter.

      Hope it helps

      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
      • A Offline
        A Offline
        ASxa86
        wrote on last edited by
        #3

        Hey, thanks for the help. That appears to be working somewhat.

        Next question, what about enums? Can I set up a Q_PROPERTY for enums? Documentation says I can only register types with a public ctor, copy-ctor, and a dtor.

        Also, just in case, I got my time value to appear in the property sheet but it seems I can't change the value. No matter what I attempt to set the value to, it defaults back to a very large garbage number.

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

          You have an example of that shown in the "Property System" chapter in the part "A simple example"

          Are you sure you are setting and returning the value correctly from your class ?

          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