Search code examples
javascriptqtqmlmultiple-value

return value from JS in QML from in QT fail


I'm trying simple function but nothing is return from function, but the "console log return the good values, what is wrong on my code please?...

JS:

function potentieldated(Pimmatriculation, Pdateinstallation)
{
    var db = dbGetHandle()
    db.transaction(function (tx) {
        var results = tx.executeSql(
                    'SELECT * FROM (SELECT * FROM (SELECT  date_etape, heure_depart, heurecellule, cyclecellule from flight_log where immatriculation=? and date_etape <= ? ORDER by heure_depart desc) ORDER by date_etape desc limit 1)UNION ALL SELECT  "0", "0", "0", "0" LIMIT 1 ' , [Pimmatriculation, Pdateinstallation])
        var heurecellule= results.rows.item(0).heurecellule;
        var cyclecellule= results.rows.item(0).cyclecellule;
        console.log("heurecellule JS " + heurecellule);
        console.log("cyclecellule JS "+ cyclecellule);
        return {heurecellule:heurecellule,cyclecellule:cyclecellule}
    })
}

QML form:

var potentiel= JS.potentieldated(stringVariable,dateaircraftpartinstallation)
var heure = potentiel.heurecellule
var cycle = potentiel.cyclecellule
console.log("heure "+heure)
console.log("cycle "+cycle)

console.log message:

qml: heurecellule JS 14010.25
qml: cyclecellule JS 4672
qrc: Cannot read property 'heurecellule' of undefined

Could You Help me please?

thank you very much


Solution

  • You don't return the value from the correct function:

    function potentieldated(Pimmatriculation, Pdateinstallation) {
        var heurecellule = 0
        var cyclecellule = 0
        var db = dbGetHandle()
        db.transaction(function (tx) {
            var results = // ...
            heurecellule = results.rows.item(0).heurecellule;
            cyclecellule = results.rows.item(0).cyclecellule;
        })
        return {heurecellule:heurecellule,cyclecellule:cyclecellule}
    }