javascript - 从 QT 中的 QML 中的 JS 返回值失败

标签 javascript qt qml multiple-value

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

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)

控制台.日志消息:

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

你能帮我吗?

非常感谢

最佳答案

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

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

关于javascript - 从 QT 中的 QML 中的 JS 返回值失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49697520/

相关文章:

qt - 如何让QToolButton超出QToolbar的边缘?

c++ - 错误:命名空间 'enable_if_t'中没有名为 'std'的模板;你是说 'enable_if'吗?

python - PySide:将数据从 QML 传递到 Python

javascript - 隐藏系列而不隐藏 y 轴

javascript - 图像未加载并插入数组(javascript)

javascript - 由于r.js将AMD模块编译成一个大文件,那么Asynchronous Module Definition中的 "asynchronous"在哪里呢?

javascript - 如何随机化段落中的字间距?

qt - Qt 中插件的自定义信号

qt - 在 QML 中绘制简单的条形图

qt - QML StackView如何推送在单独文件中定义的组件?