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. summation of value in listview
Forum Updated to NodeBB v4.3 + New Features

summation of value in listview

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 992 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.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by aha_1980
    #1

    I get these list model ..

    import QtQuick 2.0
    
    ListModel {
        ListElement {
            number: "amber"
            events: "0"
            delayM: 0
        }
        ListElement {
            number: "john"
            events: "0"
            delayM: 0
        }
        ListElement {
            number: "karl"
            events: "4"
            delayM: 43
        }
        ListElement {
            number: "sara"
            events: "0"
            delayM: 0
        }
        ListElement {
            number: "maria"
            events: "2"
            delayM: 11
        }
    }
    

    for sure I get my list view .... but I need to do a sum with delayM value when I refresh my listview .... a pieces of my listview code:

            Row {
                id: rowList
                width: 960
                height: 200
                clip: true
    
                ListView {
                    id: mylistView
                    width: 310
                    height: 180
                    clip: true
                    contentHeight: 180
                    contentWidth: 320
                    spacing: 10
                    model: myListmodel {}
                    delegate: Component {
                        Row {
                            spacing: 50
                            Column {
                                spacing: 5
                                Text {
                                    text: number;
                                    font.pointSize: 12
                                    font.family: "Arial"
                                    font.bold: true
                                }
                                Text {
                                    horizontalAlignment: Text.AlignRight
                                    text: {
                                        if(events === "0"){
                                            qsTr("all ok")
                                        }
                                        else{
                                            qsTr(events + " events")
                                        }
                                    }
                                    leftPadding: 20
                                    font.italic: true
                                    font.family: "Arial"
                                    font.pointSize: 10
                                }
                                Text {
                                    id: totMaterial
                                    horizontalAlignment: Text.AlignRight
                                    text: {
                                        if(delayM === 0){
                                            qsTr("   --")
                                        }
                                        else{
                                            qsTr(delayM + " min. ")
                                            //totRitMat = totRitMat + delayM /* error loop text*/
                                        }
                                    }
                                    leftPadding: 20
                                    font.italic: true
                                    font.pointSize: 10
                                    font.family: "Arial"
                                }
                            }
                        }
                        //onCompleted: totRitMat = totRitMat + totMaterial /* these is wrong*/
                    }
    
                }
    

    is possible to do these?

    regards

    bkt

    1 Reply Last reply
    0
    • Shrinidhi UpadhyayaS Offline
      Shrinidhi UpadhyayaS Offline
      Shrinidhi Upadhyaya
      wrote on last edited by
      #2

      Hi @gfxx ,

      Please have a look at the sample code:-

       Row {
                  id: rowList
              
                  property int totalVal: 0
                  [..]
                  [..]
      
       Text {
                id: totMaterial
                horizontalAlignment: Text.AlignRight
                text: {
                              if(delayM === 0) {
                                  qsTr("   --")
                              } else {
                                   qsTr(delayM + " min. ") + 
                                    (rowList.totalVal =  rowList.totalVal + delayM)
                               }
                           }
                  [..]
                  [..]
      

      Shrinidhi Upadhyaya.
      Upvote the answer(s) that helped you to solve the issue.

      gfxxG 1 Reply Last reply
      0
      • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

        Hi @gfxx ,

        Please have a look at the sample code:-

         Row {
                    id: rowList
                
                    property int totalVal: 0
                    [..]
                    [..]
        
         Text {
                  id: totMaterial
                  horizontalAlignment: Text.AlignRight
                  text: {
                                if(delayM === 0) {
                                    qsTr("   --")
                                } else {
                                     qsTr(delayM + " min. ") + 
                                      (rowList.totalVal =  rowList.totalVal + delayM)
                                 }
                             }
                    [..]
                    [..]
        
        gfxxG Offline
        gfxxG Offline
        gfxx
        wrote on last edited by
        #3

        @Shrinidhi-Upadhyaya i obtain these error: QML QQuickText: Binding loop detected for property "text"

        but it make the summation.

        bkt

        1 Reply Last reply
        0
        • Shrinidhi UpadhyayaS Offline
          Shrinidhi UpadhyayaS Offline
          Shrinidhi Upadhyaya
          wrote on last edited by
          #4

          Hi @gfxx , iam sorry for that, did not see that

          Here is the sample code:-

          Text {
                     id: totMaterial
                          horizontalAlignment: Text.AlignRight
          
                          text: delayM === 0
                                    ? qsTr(" --")
                                    : qsTr(delayM + " min. ") + rowList.totalVal
                                             
                           Component.onCompleted: {
                                    rowList.totalVal =  rowList.totalVal + delayM
                            }
                    }
          

          I guess this will fix the Binding loop error.

          Shrinidhi Upadhyaya.
          Upvote the answer(s) that helped you to solve the issue.

          gfxxG 1 Reply Last reply
          2
          • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

            Hi @gfxx , iam sorry for that, did not see that

            Here is the sample code:-

            Text {
                       id: totMaterial
                            horizontalAlignment: Text.AlignRight
            
                            text: delayM === 0
                                      ? qsTr(" --")
                                      : qsTr(delayM + " min. ") + rowList.totalVal
                                               
                             Component.onCompleted: {
                                      rowList.totalVal =  rowList.totalVal + delayM
                              }
                      }
            

            I guess this will fix the Binding loop error.

            gfxxG Offline
            gfxxG Offline
            gfxx
            wrote on last edited by
            #5

            @Shrinidhi-Upadhyaya said in summation of value in listview:

            Text {
            id: totMaterial
            horizontalAlignment: Text.AlignRight

                        text: delayM === 0
                                  ? qsTr(" --")
                                  : qsTr(delayM + " min. ") + rowList.totalVal
                                           
                         Component.onCompleted: {
                                  rowList.totalVal =  rowList.totalVal + delayM
                          }
                  }
            

            Yes it fix ..... (with c++ or java style if statement) ... but my intention it is write the code in these manner:

            Text {
                       id: totMaterial
                            horizontalAlignment: Text.AlignRight
            
                            text: delayM === 0
                                      ? qsTr(" --")
                                      : qsTr(delayM + " min. ")   /* not here the summation + rowList.totalVal*/
                                               
                             Component.onCompleted: {
                                      rowList.totalVal =  rowList.totalVal + delayM
                                      console.log("my first add value: " + rowList.totalVal ) /* I think is possible to see all value .... but I see only the first NON zero ... all other I not can see ... so if I would to show the summation in other place I can't  :( */
                              }
                      }
            

            bkt

            gfxxG 1 Reply Last reply
            0
            • gfxxG gfxx

              @Shrinidhi-Upadhyaya said in summation of value in listview:

              Text {
              id: totMaterial
              horizontalAlignment: Text.AlignRight

                          text: delayM === 0
                                    ? qsTr(" --")
                                    : qsTr(delayM + " min. ") + rowList.totalVal
                                             
                           Component.onCompleted: {
                                    rowList.totalVal =  rowList.totalVal + delayM
                            }
                    }
              

              Yes it fix ..... (with c++ or java style if statement) ... but my intention it is write the code in these manner:

              Text {
                         id: totMaterial
                              horizontalAlignment: Text.AlignRight
              
                              text: delayM === 0
                                        ? qsTr(" --")
                                        : qsTr(delayM + " min. ")   /* not here the summation + rowList.totalVal*/
                                                 
                               Component.onCompleted: {
                                        rowList.totalVal =  rowList.totalVal + delayM
                                        console.log("my first add value: " + rowList.totalVal ) /* I think is possible to see all value .... but I see only the first NON zero ... all other I not can see ... so if I would to show the summation in other place I can't  :( */
                                }
                        }
              
              gfxxG Offline
              gfxxG Offline
              gfxx
              wrote on last edited by
              #6

              @gfxx OK OK i see .... if scroll the listView appear the other value .....

              So the right question is How to iterate trought the listwies for to have the summation of delayM value??

              (sorry for the bad english ...)

              bkt

              1 Reply Last reply
              0
              • Shrinidhi UpadhyayaS Offline
                Shrinidhi UpadhyayaS Offline
                Shrinidhi Upadhyaya
                wrote on last edited by
                #7

                Hi @gfxx , do you mean to tell you want to access the value of delayM at a particular index or something?

                Here is the sample code for that:-

                 Component.onCompleted: {
                                        for(var i=0;i<dummyModel.count;i++) {
                                            console.log("Index:",i)
                                            console.log("Value:",dummyModel.get(i).delayM)
                                        }
                                    }
                

                Shrinidhi Upadhyaya.
                Upvote the answer(s) that helped you to solve the issue.

                1 Reply Last reply
                2

                • Login

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