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. custom model isn't completely working
Forum Updated to NodeBB v4.3 + New Features

custom model isn't completely working

Scheduled Pinned Locked Moved Solved General and Desktop
30 Posts 5 Posters 2.7k 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.
  • JoeCFDJ JoeCFD

    @mzimmers What is the role type of drawer? I guess there is a default role.

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

    @JoeCFD I don't assign any role to anything in the drawer. I'm not sure how I'd even do that as it relates to the Switch it contains.

    1 Reply Last reply
    0
    • mzimmersM mzimmers

      Another data point in this little mystery: I have 3 locations in my GUI that show the value of this model element. Two are in ordinary screens, and they're not updating correctly. The third is in a drawer, and it's always correct. The Switch code is virtually identical. Does the act of opening a drawer force an update to its contents? Is that why that one is always right?

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #22

      @mzimmers said in custom model isn't completely working:

      Does the act of opening a drawer force an update to its contents?

      possibly that opening the drawer recreates the drawer content, forcing a reload of the data each time its opened


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      mzimmersM 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @mzimmers said in custom model isn't completely working:

        Does the act of opening a drawer force an update to its contents?

        possibly that opening the drawer recreates the drawer content, forcing a reload of the data each time its opened

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

        @J-Hilk well, in a sense, that's good news -- it would mean that my model isn't properly signaling changes at all, so at least the problem is consistent.

        This is so weird -- it's almost as though the Switches on the different screens are independent of each other. Everything in the model seems to be working, from messaging the server, to accepting the response and (seemingly) sending the appropriate signals to QML.

        I know this idea is a cheat, and I wouldn't want to use it in production, but...is there a way to force a QML component to update every time it becomes visible?

        JoeCFDJ 1 Reply Last reply
        0
        • mzimmersM mzimmers

          @J-Hilk well, in a sense, that's good news -- it would mean that my model isn't properly signaling changes at all, so at least the problem is consistent.

          This is so weird -- it's almost as though the Switches on the different screens are independent of each other. Everything in the model seems to be working, from messaging the server, to accepting the response and (seemingly) sending the appropriate signals to QML.

          I know this idea is a cheat, and I wouldn't want to use it in production, but...is there a way to force a QML component to update every time it becomes visible?

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #24

          @mzimmers

           onVisibleChanged: {
                console.log( " visible =", visible )
                //do update if visible is true 
           }
          
          mzimmersM 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            @mzimmers

             onVisibleChanged: {
                  console.log( " visible =", visible )
                  //do update if visible is true 
             }
            
            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #25

            @JoeCFD the Creator doesn't like the "do update" construct; am I supposed to replace update with something?

            JoeCFDJ 1 Reply Last reply
            0
            • mzimmersM mzimmers

              @JoeCFD the Creator doesn't like the "do update" construct; am I supposed to replace update with something?

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by
              #26

              @mzimmers these are only texts. You do your update there.

              mzimmersM 1 Reply Last reply
              0
              • JoeCFDJ JoeCFD

                @mzimmers these are only texts. You do your update there.

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

                @JoeCFD OK, but what is the command to force the update?

                Here's what's happening: in my model, I make the change at the appropriate time:

                if (m_list->setItemAt(i, itemFromList)) {
                    QModelIndex qmi = index(i, 0, QModelIndex());
                    setData(qmi, itemFromList.powerState(), StateRole);
                    qDebug() << __PRETTY_FUNCTION__ << "changed powerState to" << itemFromList.powerState();
                }
                

                And in a qml screen, I have this code:

                Text { text: "equipmentModel.getEquipmentItem(pumpUuid).powerState is " + equipmentModel.getEquipmentItem(pumpUuid).powerState }
                

                This line is NOT reflecting the change made above. Somewhere there's a disconnect between the change, and the QML, but it seems like the model is doing everything correctly.

                JoeCFDJ 1 Reply Last reply
                0
                • mzimmersM mzimmers

                  @JoeCFD OK, but what is the command to force the update?

                  Here's what's happening: in my model, I make the change at the appropriate time:

                  if (m_list->setItemAt(i, itemFromList)) {
                      QModelIndex qmi = index(i, 0, QModelIndex());
                      setData(qmi, itemFromList.powerState(), StateRole);
                      qDebug() << __PRETTY_FUNCTION__ << "changed powerState to" << itemFromList.powerState();
                  }
                  

                  And in a qml screen, I have this code:

                  Text { text: "equipmentModel.getEquipmentItem(pumpUuid).powerState is " + equipmentModel.getEquipmentItem(pumpUuid).powerState }
                  

                  This line is NOT reflecting the change made above. Somewhere there's a disconnect between the change, and the QML, but it seems like the model is doing everything correctly.

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by
                  #28

                  @mzimmers in my code above you can print out the data value. If it is right, set it. If not, you have to find out the reason.

                  mzimmersM 1 Reply Last reply
                  0
                  • JoeCFDJ JoeCFD

                    @mzimmers in my code above you can print out the data value. If it is right, set it. If not, you have to find out the reason.

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

                    @JoeCFD oh, OK, I got it.

                    Text { text: "equipmentModel.getEquipmentItem(pumpUuid).powerState is " + equipmentModel.getEquipmentItem(pumpUuid).powerState }
                    
                    Switch_custom {
                        id: sw
                        checked: equipmentModel.getEquipmentItem(pumpUuid).powerState === 1
                        onClicked: {
                            if (switchState === 1) {
                                switchState = 0;
                            } else {
                                switchState = 1;
                            }
                            equipmentModel.sendSwitchChange(pumpUuid, switchState)
                            console.log("Infoscreen.qml: new switch state is " + switchState)
                        }
                        onVisibleChanged: {
                            console.log( "InfoScreen: Switch_custom visible =", visible)
                            if (visible) {
                                checked = equipmentModel.getEquipmentItem(pumpUuid).powerState === 1
                            }
                        }
                    }
                    

                    The forced update to the checked property of the Switch is working, so the powerState value is good. But the line of text above it (which should reflect the same value) still shows the old value of powerState.

                    It almost seems that my equipmentItem (the class that the list is composed of) needs to emit a signal when something changes, but my equipmentItem is just a Q_GADGET, so it can't emit signals. In the example, the list item is just a struct, so it's obviously not emitting a signal.

                    Aargh...

                    mzimmersM 1 Reply Last reply
                    0
                    • mzimmersM mzimmers

                      @JoeCFD oh, OK, I got it.

                      Text { text: "equipmentModel.getEquipmentItem(pumpUuid).powerState is " + equipmentModel.getEquipmentItem(pumpUuid).powerState }
                      
                      Switch_custom {
                          id: sw
                          checked: equipmentModel.getEquipmentItem(pumpUuid).powerState === 1
                          onClicked: {
                              if (switchState === 1) {
                                  switchState = 0;
                              } else {
                                  switchState = 1;
                              }
                              equipmentModel.sendSwitchChange(pumpUuid, switchState)
                              console.log("Infoscreen.qml: new switch state is " + switchState)
                          }
                          onVisibleChanged: {
                              console.log( "InfoScreen: Switch_custom visible =", visible)
                              if (visible) {
                                  checked = equipmentModel.getEquipmentItem(pumpUuid).powerState === 1
                              }
                          }
                      }
                      

                      The forced update to the checked property of the Switch is working, so the powerState value is good. But the line of text above it (which should reflect the same value) still shows the old value of powerState.

                      It almost seems that my equipmentItem (the class that the list is composed of) needs to emit a signal when something changes, but my equipmentItem is just a Q_GADGET, so it can't emit signals. In the example, the list item is just a struct, so it's obviously not emitting a signal.

                      Aargh...

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

                      Hi all -

                      Thanks for all the assistance. I'm going to close this topic, even though it's not solved, because I've come to realize that my model is overly complicated, and it make it difficult for me to explain here (there are parts of it that I still don't understand).

                      So, I'm going to make the following changes to my model:

                      • use an internal QList instead of using a separate class (currently EquipmentList) for my data list.

                      • replace the EquipmentItem class with a struct, and eliminate all the now-unnecessary getters and setters.

                      Hopefully these changes will make it a lot easier to follow what's happening. If I run into trouble, I'll start a new topic...thanks again.

                      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