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. QML isn't updating nested C++ objects
Forum Updated to NodeBB v4.3 + New Features

QML isn't updating nested C++ objects

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 196 Views 2 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I'm experimenting with nested C++ objects as follows:

    class RepeatData {
        Q_GADGET
    public:
        Q_PROPERTY(QVector<bool> weekDaysSelected MEMBER m_weekDaysSelected)
        QVector<bool> m_weekDaysSelected;
        bool operator ==(const RepeatData &rhs) const;
        bool operator !=(const RepeatData &rhs) const { return !operator==(rhs); }
        friend struct Schedule;
    };
    
    struct Schedule
    {
        Q_GADGET
        QML_VALUE_TYPE(schedule)
        QML_STRUCTURED_VALUE // to allow this Q_GADGET to be instantiated in QML.
        Q_PROPERTY(RepeatData repeatData MEMBER m_repeatData)
    public:
        RepeatData m_repeatData;
    }
    

    My QML seems to read the inner value(s) OK, but when I try to modify them, they don't change (no error messages). Here's an example of what's not working:

    onButtonClicked: (index) => {
                         console.log("ScheduleRepeat.qml: weekDaysSelected is " + newSchedule.repeatData.weekDaysSelected)
                         newSchedule.repeatData.weekDaysSelected[index] = !(newSchedule.repeatData.weekDaysSelected[index])
                         console.log("ScheduleRepeat.qml: weekday button " + index + " clicked.")
                         console.log("ScheduleRepeat.qml: weekDaysSelected is " + newSchedule.repeatData.weekDaysSelected)
                     }
    

    and the output:

    qml: ScheduleRepeat.qml: weekDaysSelected is true,true,true,true,true,true,true
    qml: ScheduleRepeat.qml: weekday button 2 clicked.
    qml: ScheduleRepeat.qml: weekDaysSelected is true,true,true,true,true,true,true
    

    This QML logic was working before I introduced the internal struct.

    Any idea what I'm doing wrong here?

    Thanks...

    mzimmersM 1 Reply Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      I'm experimenting with nested C++ objects as follows:

      class RepeatData {
          Q_GADGET
      public:
          Q_PROPERTY(QVector<bool> weekDaysSelected MEMBER m_weekDaysSelected)
          QVector<bool> m_weekDaysSelected;
          bool operator ==(const RepeatData &rhs) const;
          bool operator !=(const RepeatData &rhs) const { return !operator==(rhs); }
          friend struct Schedule;
      };
      
      struct Schedule
      {
          Q_GADGET
          QML_VALUE_TYPE(schedule)
          QML_STRUCTURED_VALUE // to allow this Q_GADGET to be instantiated in QML.
          Q_PROPERTY(RepeatData repeatData MEMBER m_repeatData)
      public:
          RepeatData m_repeatData;
      }
      

      My QML seems to read the inner value(s) OK, but when I try to modify them, they don't change (no error messages). Here's an example of what's not working:

      onButtonClicked: (index) => {
                           console.log("ScheduleRepeat.qml: weekDaysSelected is " + newSchedule.repeatData.weekDaysSelected)
                           newSchedule.repeatData.weekDaysSelected[index] = !(newSchedule.repeatData.weekDaysSelected[index])
                           console.log("ScheduleRepeat.qml: weekday button " + index + " clicked.")
                           console.log("ScheduleRepeat.qml: weekDaysSelected is " + newSchedule.repeatData.weekDaysSelected)
                       }
      

      and the output:

      qml: ScheduleRepeat.qml: weekDaysSelected is true,true,true,true,true,true,true
      qml: ScheduleRepeat.qml: weekday button 2 clicked.
      qml: ScheduleRepeat.qml: weekDaysSelected is true,true,true,true,true,true,true
      

      This QML logic was working before I introduced the internal struct.

      Any idea what I'm doing wrong here?

      Thanks...

      mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #2

      found the problem - my inner == operator had a bug which was causing it to always return true.

      In debugging this, I noticed that my == operator gets called a lot more times than I'd expect. I only have 2 of these objects, and am creating a 3rd, but I must have hit a breaking point inside my comparison function 20 or more times. Does this suggest a design flaw on my part?

      Thanks...

      1 Reply Last reply
      0
      • mzimmersM mzimmers has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved