今天在实验QT 加载图片资源的时候,出现无法加载图片错误。经过在网上找了一通,找到了解决方法,当每次修改了xxx.qrc文件的时候,都需要build -> run qmake 一次。
QML中的代码如下:
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
MouseArea{
anchors.fill: parent
onClicked:
{
///Qt.quit();
}
}
Text {
id: id_first
text: qsTr("my text")
anchors.centerIn: parent
}
Rectangle{
x:parent.width - 50 // 设置矩形框的位置和大小
y:20
width: 30
height: 40
anchors.right: parent
color: "lightblue"
Text {
id: name
text: qsTr("点我")
}
MouseArea
{
anchors.fill: parent
onPressed: parent.color = "red"
onReleased: parent.color = "lightblue"
}
}
//添加图片
BorderImage {
id: showimage
source: "./images/1.png"
width: 100; height: 100
border.left: 5; border.top: 5
border.right: 5; border.bottom: 5
}
//添加动画gif图片
Rectangle{
y: 100
width: animation.width
height: animation.height + 8
AnimatedImage{
id:animation;
source: "./Loading.gif"
}
Rectangle{
property int frame : animation.frameCount
width: 4
height: 8
x:(animation.width - width) * animation.currentFrame / frame
y: animation.height
color: "red"
}
}
/**/
}