【问题标题】:return value from JS in QML from in QT fail从 QT 中的 QML 中的 JS 返回值失败
【发布时间】:2018-04-06 16:43:46
【问题描述】:

我正在尝试简单的函数,但函数没有返回任何内容,但是“控制台日志返回了正确的值,请问我的代码有什么问题?...

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 形式:

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

console.log 消息:

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

你能帮帮我吗?

非常感谢

【问题讨论】:

    标签: javascript qt qml multiple-value


    【解决方案1】:

    您没有从正确的函数返回值:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-19
      • 2016-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      相关资源
      最近更新 更多