QML component not recognized when loading from local file
-
@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 -
wrote on 23 Sept 2016, 16:44 last edited by
main.qml has
import "."
at line 2. The "." imports the current directory, so yeah, already tried that -
@nwoki Can you check if the following code prints the same path where
main.qml
is present? Add this code inmain.qml
.Component.onCompleted: { console.log(Qt.resolvedUrl(".")) }
-
wrote on 23 Sept 2016, 18:34 last edited by
i get the following output.
qml: MY RESOLVE -> file:///
So it's not reading the root dir of my qml file. How can I set it properly?
-
@nwoki I tried to create the same scenario and it worked. From where are you loading these QML files ? Can you post the whole project structure? Are there any plugins involved ?
-
wrote on 25 Sept 2016, 22:02 last edited by
@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)
-
@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)
wrote on 26 Sept 2016, 01:26 last edited byThe 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 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)
@nwoki Can you try without setting the
baseUrl
and in the following manner:QQuickView view; view.setSource(QUrl::fromLocalFile(QStringLiteral("/home/folder/main.qml")));
-
wrote on 26 Sept 2016, 08:42 last edited by
@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 :)
-
@nwoki Didn't anticipate that :D
Congratulations and Happy Coding :) -
11/11