QML component not recognized when loading from local file
-
Hi all. When loading a qml file (main.qml) from a custom directory (NOT via resource file. The qml files are not to be integrated in the application) I can't load other components in the same directory.
The QML folder is:
/folder | - main.qml - ActivationArea.qml
I can load the
main.qml
correctly but main.qml can't load theActivationArea
component.MAIN.QML
import QtQuick 2.7 import "."; Item { anchors.fill: parent; ActivationArea { id: topLeft; areaSide: currentExercise.parameter("area_width").value; x: 0; y: 0; } ActivationArea { id: center; areaSide: currentExercise.parameter("area_width").value; anchors { centerIn: parent; } } }
ACTIVATIONAREA.QML
import QtQuick 2.7 Item { id: root; property int areaSide: 0; property string baseColour: "red"; property string activeColour: "pink"; Rectangle { id: bg; color: root.baseColour; width: root.areaSide; height: root.areaSide; Behavior on color { NumberAnimation { duration: 100; } } }
The error code given is:
ActivationArea is not a type
. Any ideas on how to load my items/components?P.S : the baseUrl is set to the directory of the root of the qml files.
-
@nwoki Can you check if one of the following way works for you?
https://forum.qt.io/topic/57604/qrc-main-qml-9-gui-delegates-uepeopleitemdelegate-qml-no-such-directory-error/2 -
@p3c0 The QML files are in a folder on the desktop whilst my program is run from a different folder. The result i'm trying to achieve is that of being able to load a qml program (any folder with a bunch of QML files in it starting from a "main.qml" file) from any folder.
Yes, I use plugins but they're custom QML plugins (qqmlcomponent). Do they somehow interfere with the loading of the qml files on my desktop folder? (I use a seperate QQmlEngine for these components)
-
The result i'm trying to achieve is that of being able to load a qml program (any folder with a bunch of QML files in it starting from a "main.qml" file) from any folder.
Use a Loader and set the source to a main area of that said extra folder
example:
/home/nwoki/mainApp/ This is the folder that contains your main app. that app that is run when main.cpp inits the engine or view or whatever. Add a Loader here and get the url (for other folder )and store in c++ sa a QString or whatever
then there is this folder
/home/nwoki/Videos/QmlVideosFolder/Just map the Loader to Load from there.
-
@p3c0 said in QML component not recognized when loading from local file:
@nwoki Can you try without setting the
baseUrl
and in the following manner:QQuickView view; view.setSource(QUrl::fromLocalFile(QStringLiteral("/home/folder/main.qml")));
This was the fix. More precisely:
QUrl::fromLocalFile
I was loading the non qrc files without the "QUrl::fromLocalFile". Using this solved the qml resolve problems and I'm now able to load the extra QML components from the specified dir.
Thanks guys :)
-