i try to import(Cell.qml) in main.qml,but i'm getting this error:QML debugging is enabled. Only use this in a safe environment. QQmlApplicationEngine failed to load component qrc:/main.qml:4 "Cell.qml": no such directory
In our main QML file, we use our Cell component to create the color picker. how can i fixed that?
import QtQuick 2.9
import QtQml 2.0
import "Cell.qml"
Rectangle {
id:page
width:320;height: 480
color: "lightgray"
Text {
id: helloText
text: "Hello World";
y:30
anchors.horizontalCenter: page.horizontalCenter
font.pointSize: 24; font.bold: true
}
Grid {
id:colorPicker
x:4;anchors.bottom: page.bottom;anchors.bottomMargin: 4
rows: 2;columns: 3;spacing: 3
Cell{cellColor: "red";onClicked: helloText.color=cellColor}
Cell{cellColor: "green";onClicked: helloText.color=cellColor}
Cell{cellColor: "blue";onClicked: helloText.color=cellColor}
Cell{cellColor: "yellow";onClicked: helloText.color=cellColor}
Cell{cellColor: "steelblue";onClicked: helloText.color=cellColor}
Cell{cellColor: "black";onClicked: helloText.color=cellColor}
}
}
You need to:
Cell.qml to your qml.qrc file.Import the directory of the Cell.qml file. If Cell.qml is in relative directory ../foo/bar/widgets:
import '../foo/bar/widgets';
However, if the file is already in the same directory as your main.qml file, then you do not need to import it.
Note: only *.js files are imported with a full path name. e.g.
import "../util/util.js" as Util;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With