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. Make adding new Q_PROPERTY easy for the developer
Forum Updated to NodeBB v4.3 + New Features

Make adding new Q_PROPERTY easy for the developer

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.3k 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.
  • K Offline
    K Offline
    kortus
    wrote on last edited by
    #1

    I have a lot of classes which a lot of properties shared with QML. To define such a property there is lot of source code needed like this:
    @private:
    Q_PROPERTY(bool button1 READ getButton1 WRITE setButton1 NOTIFY button1Changed)
    public:
    bool getButton1() const { return button1; }
    signals:
    void button1Changed();
    public slots:
    void setButton1 (bool localParameter);
    private:
    bool button1;@

    The idea is to simplify this process in any way to make it easy for new developers to add a property and minimize possible naming mistakes. I started to define a macro which creates the code and is called with:

    @MYDATAPROPERTY(bool, button1, Button1)@

    This works not and I have learned from the forum that the moc compiler works before the c-preprocessor works and in this case the solution is not usable.

    Are there other methods to simplify the process of code generation?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      In Qt 5.1, you can use the new keyword: "MEMBER". I have not tested it myself, but it should make your life easier. See "this link":http://qt-project.org/wiki/New-Features-in-Qt-5.1.

      (Z(:^

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kortus
        wrote on last edited by
        #3

        Thanks for the quick response. The MEMBER keyword is helpful to share members with QML only. The member is added the the Qt meta system but no getter/setter function is generated. But we need this functions to set/get values from the C++ side.
        And it looks that the MEMBER keyword is not supported by QtCreator (2.8.1 based on Qt 5.1.1)

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          It should still be possible to use it in C++ thorough MOC (QObject::property()), although the lack of setters and getters might be unwelcome.

          If that is not enough, you can write your own code generator that will expand the macro into a set of getters and setters. Not an optimal solution, but possible. Another option would be to modify moc and push the code back to Qt Project, so that we can all benefit from it.

          (Z(:^

          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