gpt4 book ai didi

qt - Qml 项目无法编译,错误 'Expected token ` ,'

转载 作者:行者123 更新时间:2023-12-02 04:28:22 27 4
gpt4 key购买 nike

Qt Creator 3.1.2 基于 Qt 5.3.1(MSVC 2010,32 位)。项目已导入 QmlProject 2.0这是我的程序,出现此错误。这个程序来自教程,它对他有用......所以我不确定那里有什么问题。

import QtQuick 2.0

Rectangle {
id: rootTangle
width: 360
height: 360
color: "red"
hoverEnabled: true;


Rectangle {
id: blueRec
color: "blue"
//opacity: .50
width: rootTangle.width/2
height: rootTangle.width/6
anchors.centerIn: rootTangle
border.color: "black"
border.width: 7
rotation: 180
radius: 20
gradient: Gradient {
GradientStop { position: 0.0; color: "#b0c5de" }
GradientStop { position: 1.0; color: "blue" }
}
}

Text {
id: nazdarTxt
anchors.centerIn: blueRec
text: "Nazdar"
clip: false
visible: true
font.family: "Times New Roman"
font.bold: true
//font.pixelSize: Math.round(blueRec.height/3)
width: blueRec.width
//wrapMode: Text.WordWrap

}

MouseArea {
id: blueRecMouseArea
hoverEnabled: true;
onEntered: {
blueRec.color: "brown"
}

anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 1
anchors.topMargin: 0
anchors.fill: blueRec
onClicked: {
Qt.quit();

}
}

}

错误出现在第 46 行:onEntered: {
blueRec.color: "棕色"
}

最佳答案

问题出在颜色后面的冒号:

onEntered: {
blueRec.color: "brown"
}

您应该更改为等号:

onEntered: {
blueRec.color = "brown"
}

此外,矩形中没有 hoverEnabled,因此您需要将其删除或注释:

Rectangle {
id: rootTangle
width: 360
height: 360
color: "red"
//hoverEnabled: true;

由于您已经为 blueRec 定义了渐变,因此更改其颜色没有任何效果,您应该更改渐变颜色:

onEntered: {
blueRec.gradient.stops[0].color = "brown"
blueRec.gradient.stops[1].color = "white"
}

关于qt - Qml 项目无法编译,错误 'Expected token ` ,',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25259669/

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