Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QQmlApplicationEngine failed to load component

Tags:

qt

qml

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}
    }
}
like image 430
Samira Sarvi Avatar asked Sep 05 '26 03:09

Samira Sarvi


1 Answers

You need to:

  • Add 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;
like image 53
Ross Rogers Avatar answered Sep 08 '26 02:09

Ross Rogers