Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-85025

Use QDir::searchPaths for locating JS and QML modules

    XMLWordPrintable

Details

    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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            be Be Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes