Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Why are upper-cased properties not supported in QML?
Forum Update on Monday, May 27th 2025

Why are upper-cased properties not supported in QML?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 4 Posters 1.5k Views
  • 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.
  • mwallnoeferM Offline
    mwallnoeferM Offline
    mwallnoefer
    wrote on last edited by mwallnoefer
    #1

    What is the reason that Qt properties need to begin with a lower-cased letter in order to be exposed to QML?

    Example: this works

    C++

    class Model : public QAbstractListModel
    {
    ...
        Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
        Q_PROPERTY(int age READ age WRITE setAge NOTIFY ageChanged)
    ...
    };
    

    QML:

    Person {
       name: "Otto"
       age: 30
    ...
    }
    

    This not (odd error message in the QML code at runtime):

    class Model : public QAbstractListModel
    {
    ...
        Q_PROPERTY(int Name READ name WRITE setName NOTIFY nameChanged)
        Q_PROPERTY(int Age READ age WRITE setAge NOTIFY ageChanged)
    ...
    };
    

    QML:

    Person {
       Name: "Otto"
       Age: 30
    ...
    }
    
    raven-worxR 1 Reply Last reply
    0
    • mwallnoeferM mwallnoefer

      What is the reason that Qt properties need to begin with a lower-cased letter in order to be exposed to QML?

      Example: this works

      C++

      class Model : public QAbstractListModel
      {
      ...
          Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
          Q_PROPERTY(int age READ age WRITE setAge NOTIFY ageChanged)
      ...
      };
      

      QML:

      Person {
         name: "Otto"
         age: 30
      ...
      }
      

      This not (odd error message in the QML code at runtime):

      class Model : public QAbstractListModel
      {
      ...
          Q_PROPERTY(int Name READ name WRITE setName NOTIFY nameChanged)
          Q_PROPERTY(int Age READ age WRITE setAge NOTIFY ageChanged)
      ...
      };
      

      QML:

      Person {
         Name: "Otto"
         Age: 30
      ...
      }
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @mwallnoefer
      because there are default created changed-slots for each property following the pattern on<CamelCasePropertyName>Changed() (if NOTIFY was specified)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • mwallnoeferM Offline
        mwallnoeferM Offline
        mwallnoefer
        wrote on last edited by
        #3

        Okay, but it seems that also the following piece does not work or am I missing something? Also when omitting the NOTIFY clause I get always the same "Invalid attached object assignment" error.

        class Model : public QAbstractListModel
        {
        ...
            Q_PROPERTY(int Name READ Name WRITE setName NOTIFY NameChanged)
            Q_PROPERTY(int Age READ Age WRITE setAge NOTIFY AgeChanged)
        ...
        };
        

        For me this seems more like a bug, since in C++ code upper cased properties are perfectly valid. Alternatively, the docs could be updated to contain an explicit reference to this restriction of QML (for instance in the section about Q_PROPERTY):

        Julien BJ 1 Reply Last reply
        0
        • mwallnoeferM mwallnoefer

          Okay, but it seems that also the following piece does not work or am I missing something? Also when omitting the NOTIFY clause I get always the same "Invalid attached object assignment" error.

          class Model : public QAbstractListModel
          {
          ...
              Q_PROPERTY(int Name READ Name WRITE setName NOTIFY NameChanged)
              Q_PROPERTY(int Age READ Age WRITE setAge NOTIFY AgeChanged)
          ...
          };
          

          For me this seems more like a bug, since in C++ code upper cased properties are perfectly valid. Alternatively, the docs could be updated to contain an explicit reference to this restriction of QML (for instance in the section about Q_PROPERTY):

          Julien BJ Offline
          Julien BJ Offline
          Julien B
          wrote on last edited by
          #4

          Hello @mwallnoefer,

          The documentation currently refers to this in property attributes

          mwallnoeferM 1 Reply Last reply
          1
          • Julien BJ Julien B

            Hello @mwallnoefer,

            The documentation currently refers to this in property attributes

            mwallnoeferM Offline
            mwallnoeferM Offline
            mwallnoefer
            wrote on last edited by
            #5

            @Julien-B Okay, but then it should go also in the Q_PROPERTY section.

            But the interesting thing is, that person.Name or person.Age does work though. Only the class assignment syntax with the colon does not.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Thomas Hartmann
              wrote on last edited by
              #6

              Capital letter properties are reserved for so called attached properties (http://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html).

              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