Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-87865

Support c++11/c++20 templates for QObjects

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Reported
    • Priority: Not Evaluated
    • Resolution: Unresolved
    • Affects Version/s: 5.13.0 RC 3, 5.14.0 RC2, 5.15.0 RC2
    • Fix Version/s: None
    • Component/s: Build tools: moc
    • Labels:
      None
    • Platform/s:
      All

      Description

      I would like to create templated QObjects. This would allow me to create a Property structure for example. Which is fully compatible with QML without writing getters and setters and signals for each property and binding it over a Q_PROPERTY macro. Which is prone to bugs and also limits the use of all c++ features.

      For example: I would like to have something like the following:

      template <std::equality_comparable T>
      class Property : QObject<Property<T>> {
      //Q_OBJECT not required, since we use the "templated QObject"

      {{public:    }}
          T value(){...}
      slot:
          set(T&& val){...}
      signal:
          valueChanged();

      private:
          T [[Qt::Property READ }}{{value}}{{ WRITE }}{{set NOTIFY }}{{valueChanged}}{{]] value_;
      // Alternatively:
      // #pragma Qt Property }}{{READ }}{{value{{ WRITE }}{{set NOTIFY }}{{valueChanged }}
      // }}{{T value_;
      };

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            qtbuildsystem Qt Build System Team
            Reporter:
            febbe Fabian Keßler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes