Details
-
Suggestion
-
Resolution: Unresolved
-
P2: Important
-
5.13.2
Description
In my application, I am importing a JS module via QJSEngine::importModule. I would like to be able to import JS module libraries shipped with the application from that module. I would like to use QDir::setSearchPaths to create a prefix directory that the JS modules could be imported from. Unfortunately, this does not work. I verified that I used QDir::setSearchPaths correctly by creating a QFileInfo with a prefix setup by QDir::setSearchPaths and checking QFileInfo::exists(), which returned true. However, when I try to import the same path ("lib:mididispatcher.mjs") from JS, I get this error:
Error: Could not open module lib:mididispatcher.mjs for reading
I can tell it treats the prefixed path as a special path because if I exclude the prefix ("mididispatcher.mjs") I get a different error showing it tried to search a path relative to the JS file:
Error: Could not open module file:///home/be/sw/mixxx/mapping/res/controllers/xonek2/mididispatcher.mjs for reading
This leaves me with two options, neither of which are great. The libraries can be compiled into the application via the Qt Resource System but that requires the application to be recompiled when editing the libraries. The libraries can be imported with relative paths, but that requires users to copy application libraries when distributing scripts on our forum.