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

Feature Request: Add property attribute to C++ Q_PROPERTY for initializable but not resettable property

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • None
    • Build tools: moc
    • None
    • All

    Description

      Note: I was not sure which Component this feature request should be filed under, so please change to the appropriate Component.

      The REQUIRED keyword can be used to enforce objects instantiated by QML to have a specific property set. This is specially useful to replace values that would be passed to the object constructor in a typical C++ program. Furthermore, constructor arguments are typically passed for object construction and not reset again through object lifetime. To emulate the same behavior, currently one could check in the setProperty method if the component has already been initialized, and if so, not reset the property value:

      void componentComplete() // from QQmlParserStatus
      {
          // initialize resources using properties
          m_initialized = true;
      }
      
      void setSomeProperty(Type value)
      {
          if (!m_initialized)
          {
              // Log error and return
          }
          else
          {
              m_someProperty = value;
          }
      }
      

      However doing this check in every class is cumbersome and cluttering. Considering the commonality of passing constructor arguments as properties to QObject classes, and having initialize-able but not reset-able variables constructor arguments in C++, it would be great to add a Q_PROPERTY attribute, which makes the QML engine be able to instantiate the object with that property but not reset it:

      MyComp
      {
          id: myComp
          myProp: value // valid
      }
      // cannot reset
      onSignal:
      {
          myComp.myProp = newValue // invalid
      }

       

       

      Attachments

        Issue Links

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

          Activity

            People

              fabiankosmale Fabian Kosmale
              mmi_puya Puya Daravi
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes