问题
This has got to be the weirdest Qt bug I've encountered so far, an unused var in a non-executed function results in a hard crash on QQmlEngine::load()
.
It takes those few lines of code to reproduce it:
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
id: main
visible: true
width: 500
height: 300
function foo() {
var c = main.width > 1 ? 27 : -147
}
}
It crashes on both 5.7 and 5.7.1, "stock" GCC builds from the Qt website under windoze 7 x64 and ubuntu 16.04. Adding a simple console.log(c)
prevents the crash. Again, note that the function is perfectly legal, no access to any fishy objects whatsoever, and it not even being executed to produce the crash. It looks like something goes terribly wrong when the QML code is being parsed by the engine. The conditional is key here, it doesn't crash without it.
Aside from the implied "what's going on here?" I'd also would take the opportunity to ask people with different platforms or Qt versions whether it affects others, before posting a bug report.
来源:https://stackoverflow.com/questions/41498916/unused-js-var-in-unused-function-conditional-causes-qqmlengine-to-crash-on-loa