import of qml modules only works with full paths?!

• Aug 12, 2019 - 10:37

You can import directories with qml modules and then use the definitions found there, eg:
import "file:///home/username/MuseScore2/Plug-Ins/QMLImporting/"
where QMLImporting contains the qml files, eg. "MyRect.qml"

This works perfectly if you specify a full path with the prefix "file://"

Relative paths don't work at all. They all result in breaking errors like "Komponente erzeugen schlug fehl" / "has no qmldir and no namespace" / "no such directory" OR the definitions are not found, eg. message "MyRect is not a type".

I also have copied "MyRect.qml" to any directory imaginable - doesn't work either:
Inside the same dir as the calling plugin, any directory inside Plug-Ins, MuseScore dirs, not working.

Also tried to set the environment variable QML_IMPORT_PATH - not working

same problem
- for MS2/MS3
- for linux, Ubuntu/Windows
- for importing of JavaScript files.
- for Loader, although you can solve the problem procedurally - which is still not desirable

Has anybody ever found a solution for this? Is this working Am I doing something wrong?


In reply to by BSG

Nope - doesn't work...
import "MyRect.qml"
results in a message "MyRect is not a type"

If you combine the full path with the actual qml fileName eg.:
import "file:///home/username/MuseScore2/Plug-Ins/QMLImporting/MyRect.qml"
then you'll get the message "no such directory"

It drives me nuts...
Do I have to create all-in-one-file-code?

In reply to by Ziya Mete Demircan

Nope - this results in no error on loading but MyRect is still not found -> "MyRect is not a type"
you may append a slash - same game.

If you try to import into namespace:
import "./components" as Test
and then use Test.MyRect
I get "Test.MyRect unavailable, Network Error"

Trying to load with the fileName appended (./components/MyRect.qml) results always in "creating component failed"

In reply to by marlovitsh

I don't know the contents of the file you're trying to import, so I'm giving you guesses:

I can think of:

a) Try using the component name you created in that (imported) file directly, not the file name you imported.

b) or define the file name as the component name,

MyRect MyRect.qml
import "./mySubdir"


and use MyRect as a component.

do they work?

In reply to by Ziya Mete Demircan

I just try to do it as defined in the docs which works just perfect with a full path(!)

The file to imported (MyRect.qml) is quite simple - it just contains a red Rectangle. See the attachment.

a) I can't use the component name directly since this would be "Rectangle" which is already defined by Qt. if I try to import into a namespace to define which Rectangle to use, eg with import "./components" as Test then both Test.MyRect and Test.Rectangle do not work -> "Test.MyRect unavailable, Network error"

b) I don't know how to define the file name as the component name - what should I try exactly?

Attachment Size
MyRect.qml 87 bytes

In reply to by marlovitsh

I think you're trying to implement QML examples.
You should try these in QT applications, not in Musescore.
Because Musescore runs this plugin system by adapting it.
I think your application will not work in the MuseScore { } field.

Or someone who is more knowledgeable than me with musescore plugins can answer you.

In reply to by Ziya Mete Demircan

Nope - I'm not implementing QML examples, no Qt Application.
I'm writing plugins for MuseScore, so I need to implement it in MuseScore {}. Almost finished, just cleaning up.
And - as I already said - everything works just perfect, even importing qml/JavaScript - but both only with absolute paths.
That means that this importing part actually IS working fine as it is expected to.

May be someone knows the base directory from which relative paths are calculated?
Any restrictions in MuseScore's implementation preventing to use relative paths?
Could/should be found in the C++ source probably.

Thanks anyway, Harry

Do you still have an unanswered question? Please log in first to post your question.