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. progressBar value from for loop?
Forum Updated to NodeBB v4.3 + New Features

progressBar value from for loop?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 711 Views 4 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.
  • F Offline
    F Offline
    filipdns
    wrote on last edited by filipdns
    #1

    Hello,

    I have value change inside for loop and I want to use it to change my progressbar value in QML, How can I do that?

    Thank you for your help!!

    function tableupdate()
            {
                for( var i =listView.currentRow ; i > 0; i--)
                {
    
                    JS.dbimmat(stringVariable4)
                    var j = i-1
                    var date_etape_readed1 = listView.model.get(j).date_etape
                    var date_etape_readed2 = listView.model.get(i).date_etape
                    var heure_depart_readed1 = listView.model.get(j).heure_depart
                    var heure_depart_readed2 = listView.model.get(i).heure_depart
                    var heure_arrivee_readed1 = listView.model.get(j).heure_arrivee
                    var heure_arrivee_readed2 = listView.model.get(i).heure_arrivee
                    var hour = parseFloat(listView.model.get(j).temps_bloc_etape)
                    var cycle = parseInt(listView.model.get(j).cycle_etape)
                    var sunsetofday
                    var sunriseofday
    
                        sunsetofday = Qt.formatDateTime(new Date(date_etape_readed1).sunset(49.264063, 2.513419),"hh:mm")
                        sunriseofday= Qt.formatDateTime(new Date(date_etape_readed1).sunrise(49.264063, 2.513419),"hh:mm")
                        var nighttime = JS1.nighttime(heure_depart_readed1,heure_arrivee_readed1,sunsetofday, sunriseofday)
                        var temps_bloc_etape = JS1.substractionhours(heure_arrivee_readed1,heure_depart_readed1)
                        var temps_bloc_jour = JS1.hourtodec(JS1.substractionhours(temps_bloc_etape,JS1.decimalToHour(nighttime)))
    
    
                    JS.dbtimeUpdateflightlog(
                                sunriseofday,
                                sunsetofday,
                                JS1.precisionRound(JS1.hourtodec(temps_bloc_etape),3),
                                JS1.precisionRound(temps_bloc_jour,3),
                                JS1.precisionRound(nighttime,3),
                                JS1.precisionRound(parseFloat(listView.model.get(i).heurecellule)+hour,3),
                                parseInt(listView.model.get(i).cyclecellule)+cycle,
                                JS1.precisionRound(parseFloat(listView.model.get(i).heure_SN_moteur_1)+hour,3),
                                parseInt(listView.model.get(i).cycle_SN_moteur_1)+cycle,
                                JS1.precisionRound(parseFloat(listView.model.get(i).heure_SN_moteur_2)+hour,3),
                                parseInt(listView.model.get(i).cycle_SN_moteur_2)+cycle,
                                listView.model.get(j).id
                                )
                    listView.model.clear()
                    JS.dbimmat(stringVariable4)
                   progressbar.value=((listView.currentRow-i)/(listView.currentRow-1))
                }
            }
    
    ProgressBar{
        id:progressbar
        value:0
    }
    
    
    
    
    raven-worxR 1 Reply Last reply
    0
    • F filipdns

      Hello,

      I have value change inside for loop and I want to use it to change my progressbar value in QML, How can I do that?

      Thank you for your help!!

      function tableupdate()
              {
                  for( var i =listView.currentRow ; i > 0; i--)
                  {
      
                      JS.dbimmat(stringVariable4)
                      var j = i-1
                      var date_etape_readed1 = listView.model.get(j).date_etape
                      var date_etape_readed2 = listView.model.get(i).date_etape
                      var heure_depart_readed1 = listView.model.get(j).heure_depart
                      var heure_depart_readed2 = listView.model.get(i).heure_depart
                      var heure_arrivee_readed1 = listView.model.get(j).heure_arrivee
                      var heure_arrivee_readed2 = listView.model.get(i).heure_arrivee
                      var hour = parseFloat(listView.model.get(j).temps_bloc_etape)
                      var cycle = parseInt(listView.model.get(j).cycle_etape)
                      var sunsetofday
                      var sunriseofday
      
                          sunsetofday = Qt.formatDateTime(new Date(date_etape_readed1).sunset(49.264063, 2.513419),"hh:mm")
                          sunriseofday= Qt.formatDateTime(new Date(date_etape_readed1).sunrise(49.264063, 2.513419),"hh:mm")
                          var nighttime = JS1.nighttime(heure_depart_readed1,heure_arrivee_readed1,sunsetofday, sunriseofday)
                          var temps_bloc_etape = JS1.substractionhours(heure_arrivee_readed1,heure_depart_readed1)
                          var temps_bloc_jour = JS1.hourtodec(JS1.substractionhours(temps_bloc_etape,JS1.decimalToHour(nighttime)))
      
      
                      JS.dbtimeUpdateflightlog(
                                  sunriseofday,
                                  sunsetofday,
                                  JS1.precisionRound(JS1.hourtodec(temps_bloc_etape),3),
                                  JS1.precisionRound(temps_bloc_jour,3),
                                  JS1.precisionRound(nighttime,3),
                                  JS1.precisionRound(parseFloat(listView.model.get(i).heurecellule)+hour,3),
                                  parseInt(listView.model.get(i).cyclecellule)+cycle,
                                  JS1.precisionRound(parseFloat(listView.model.get(i).heure_SN_moteur_1)+hour,3),
                                  parseInt(listView.model.get(i).cycle_SN_moteur_1)+cycle,
                                  JS1.precisionRound(parseFloat(listView.model.get(i).heure_SN_moteur_2)+hour,3),
                                  parseInt(listView.model.get(i).cycle_SN_moteur_2)+cycle,
                                  listView.model.get(j).id
                                  )
                      listView.model.clear()
                      JS.dbimmat(stringVariable4)
                     progressbar.value=((listView.currentRow-i)/(listView.currentRow-1))
                  }
              }
      
      ProgressBar{
          id:progressbar
          value:0
      }
      
      
      
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @filipdns
      like in C++ your operation blocks the painting thread and thus there is no update of the screen.
      In QML you can use so called WorkerScripts to move a long running operation into the background. See this example.

      --- 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

      F 1 Reply Last reply
      4
      • raven-worxR raven-worx

        @filipdns
        like in C++ your operation blocks the painting thread and thus there is no update of the screen.
        In QML you can use so called WorkerScripts to move a long running operation into the background. See this example.

        F Offline
        F Offline
        filipdns
        wrote on last edited by filipdns
        #3

        @raven-worx thanks a lot for your reply but it's not working...

        using console.log to see the result, without workerScript, I got only the last result of the calculation, then only one line. The only difference with the WorkerScript that is I get all line but in one time and stay at the end of the loop...
        here the qml file:

         WorkerScript {
                        id: myWorker
                        source: "timecalculation.js"
                        onMessage: {console.log(messageObject.reply)}
                }
        
        
        
        
                function tableupdate()
                {
                    for( var i =listView.currentRow ; i > 0; i--)
                    {
        
                        JS.dbimmat(stringVariable4)
                        var j = i-1
                        var date_etape_readed1 = listView.model.get(j).date_etape
                        var date_etape_readed2 = listView.model.get(i).date_etape
                        var heure_depart_readed1 = listView.model.get(j).heure_depart
                        var heure_depart_readed2 = listView.model.get(i).heure_depart
                        var heure_arrivee_readed1 = listView.model.get(j).heure_arrivee
                        var heure_arrivee_readed2 = listView.model.get(i).heure_arrivee
                        var hour = parseFloat(listView.model.get(j).temps_bloc_etape)
                        var cycle = parseInt(listView.model.get(j).cycle_etape)
                        var sunsetofday
                        var sunriseofday
        
                            sunsetofday = Qt.formatDateTime(new Date(date_etape_readed1).sunset(49.264063, 2.513419),"hh:mm")
                            sunriseofday= Qt.formatDateTime(new Date(date_etape_readed1).sunrise(49.264063, 2.513419),"hh:mm")
                            var nighttime = JS1.nighttime(heure_depart_readed1,heure_arrivee_readed1,sunsetofday, sunriseofday)
                            var temps_bloc_etape = JS1.substractionhours(heure_arrivee_readed1,heure_depart_readed1)
                            var temps_bloc_jour = JS1.hourtodec(JS1.substractionhours(temps_bloc_etape,JS1.decimalToHour(nighttime)))
        
                        JS.dbtimeUpdateflightlog(
                                    sunriseofday,
                                    sunsetofday,
                                    JS1.precisionRound(JS1.hourtodec(temps_bloc_etape),3),
                                    JS1.precisionRound(temps_bloc_jour,3),
                                    JS1.precisionRound(nighttime,3),
                                    JS1.precisionRound(parseFloat(listView.model.get(i).heurecellule)+hour,3),
                                    parseInt(listView.model.get(i).cyclecellule)+cycle,
                                    JS1.precisionRound(parseFloat(listView.model.get(i).heure_SN_moteur_1)+hour,3),
                                    parseInt(listView.model.get(i).cycle_SN_moteur_1)+cycle,
                                    JS1.precisionRound(parseFloat(listView.model.get(i).heure_SN_moteur_2)+hour,3),
                                    parseInt(listView.model.get(i).cycle_SN_moteur_2)+cycle,
                                    listView.model.get(j).id
                                    )
                        myWorker.sendMessage({'val':String((listView.currentRow-i)/(listView.currentRow-1))})
                            listView.model.clear()
                            JS.dbimmat(stringVariable4)
                    }
                }
        

        here the timecalculation.js:

        WorkerScript.onMessage = function(message) {
            //Send result back to main thread
            WorkerScript.sendMessage( {'reply': message.val} );
        }
        
        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