为什么在点击“运行"时有时不会反映 QML 代码的更改以及如何解决它? [英] Why are changes to the QML code sometimes not reflected when hitting 'Run' and how to solve it?
问题描述
在这个 Qt Quick 简单示例中,我希望当我向上移动 Racked 时,我们在 console.log 上有一条消息显示该移动,而当 Racket 向下移动时,我们有另一条消息.我为此编写了此代码:
In this Qt Quick simple example, I want that when I move a Racked upwards, we have a message on console.log showing that movement and another message when the Racket is moved downwards. I've written this code for that:
Racket.qml
:
import QtQuick 2.8
Rectangle {
id: root
width: 15; height: 50
x: 400; y: 100
color: "red"
property int oldY: 100
property bool yUwards: false
property bool yDwards: false
onYChanged: {
if( y > oldY) {
yDwards = true
yUwards = false
console.log("Racket moved downwards.\n")
}
else if( y < oldY) {
yDwards = false
yUwards = true
console.log("Racket moved upwards.\n")
}
oldY = y
}
MouseArea {
anchors.fill: parent
drag.target: root
drag.axis: Drag.YAxis
drag.minimumY: 10
drag.maximumY: 440
}
}
main.qml
:
import QtQuick 2.8
import QtQuick.Window 2.2
Window {
visible: true
width: 800
height: 600
Rectangle {
id: table
width: 700; height: 500
border.width: 10
border.color: "black"
color: "white"
Racket {
id: redRacket
x: 630; y: 100
color: "red"
}
}
}
当我第一次点击Run
时,代码不起作用,所以我点击clean all
,run qmake
然后全部重建
,然后就成功了!
像我这样的 QML 新程序员是如何发现代码没问题的,但是成功运行程序需要这个过程?
When I at the first time hit Run
, the code didn't work, so I hit clean all
, run qmake
and then rebuild all
, then it worked!
How does a new QML programmer like me figure out that the code is fine but this process is needed to successfully run the program?
推荐答案
这确实是 QMake 中的一个错误.正如@Mitch 在他的评论中发布的那样,已经提交了一个错误报告:bugreports.qt.io/browse/QTBUG-13334
This is indeed a bug in QMake. As @Mitch posted in his comment, a bug report was already filed: bugreports.qt.io/browse/QTBUG-13334
如果您通读了该错误报告中的评论,则会发布该问题的解决方法.已经使用它几个月了,它似乎解决了这个问题.您所要做的就是将其粘贴到您的专业文件的末尾.
If you read through the comments in that bug report, a workaround for the problem was posted. Have been using it for a couple of months now and it seems to fix the issue. All you have to do is paste this at the end of your pro file.
#update qml
qml_scenes.depends = $$PWD/resources/scene1.qml $$PWD/resources/scene2.qml ...
qml_scenes.commands =
QMAKE_EXTRA_TARGETS += qml_scenes
这篇关于为什么在点击“运行"时有时不会反映 QML 代码的更改以及如何解决它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!