gpt4 book ai didi

javascript - Qt QML 中疯狂字符串数字比较的解决方法

转载 作者:数据小太阳 更新时间:2023-10-29 06:15:02 26 4
gpt4 key购买 nike

这是 Qt (LTS 5.6.2) QML JavaScript 实现中疯狂的字符串与数字比较:

console.log("240000000000" == "3776798720");
console.log("240000000000" === "3776798720");
console.log("240000000000" === "3776798721");

输出是:

true
true
false

看起来字符串被解释为 (u)int32 并且丢失了高字节:

240000000000 == 0x37E11D6000
3776798720 == 0xE11D6000

此错误也会影响对象:

var g = {};
var h = "240000000000";
g[h] = h + "BUG";
console.log(JSON.stringify(g, null, 2));
console.log(g["3776798720"], g["240000000000"]);

输出:

qml: {
"3776798720": "240000000000BUG"
}
qml: 240000000000BUG 240000000000BUG

如您所见, key 已损坏。可以通过两个不同的字符串获取值。

问题

有没有办法在不给 Qt 打补丁的情况下解决这个问题?或至少 Qt 中可能存在问题的大致位置以提高您自己?

附注这里还有一个 QTBUG-56830我的同事报告的。

最佳答案

我看不到解决方法,所以我做了一个修复:将我在此处发布的补丁应用到 qtdeclarative

https://codereview.qt-project.org/#/c/175782

然后重新编译。

关于javascript - Qt QML 中疯狂字符串数字比较的解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40357838/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com