progressBar value from for loop?



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

  • Moderators

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



  • @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} );
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.