Something about module import paths changed in Qt5.9.1? (Uppercase squashed to lowercase?)



  • This is a weird one.

    I have a Qt (QML in a QQuickView host) app with a long history. It's been left to languish on Qt5.7 but recently I've got interested in updating it to a newer version. It works when I build it with Qt versions 5.7, 5.8 & 5.9(.0)... but when I build it vs. anything after that (e.g 5.9.1) I start seeing an issue which suggests something changed about the handling of import paths and their case sensitivity. (I'm building on Linux BTW).

    My app has a directory MyAppContent/ with some javascript and QML files and a qmldir containing

    module MyAppContent
    MyMessages 1.0 MyMessages.js
    

    (and some additional .js lines) which is all baked into the app resources as qrc:///MyAppContent/...

    In the working versions QML files using import MyAppContent 1.0 Just Work. But from 5.9.1 onwards (5.9.2, 5.9.3 and 5.9.4 all tried) I get the curious message qrc://myappcontent/MyMessages.js: file to open is a directory and QML which tries to import MyAppContent fails to load. It's curious because of the way that myappcontent has apparently been squashed from MyAppContent. Certainly my code doesn't contain the string myappcontent anywhere... it's always MyAppContent.

    Browsing around the documentation for QML modules and import I can't find anything which convinces me one way or the other. There's an example at the end of this page which seems to show exactly what I'm doing (it wouldn't be the first time documentation has lagged behind changes to the reality though). And I can't spot anything obviously relevant in the 5.9.1 changelogs. On the other hand the mention of these module identifiers being URIs makes me wonder whether some sort of case-insensitive handling of URIs has crept in to cause trouble.

    Any ideas?



  • Hmmm... I threw together a simplified standalone testcase I thought should demonstrate the problem... and it worked fine with all versions of Qt I tried from 5.7 to 5.9.4. So it's not as simple as module names getting downcased. Investigations continue....



  • Aha... think I have it figured out...

    To enable the QML engine find the module in the resources, I've always found its been necessary to use one of these lines (some background):

    viewer.engine()->addImportPath("qrc:/");      // Works on Qt 5.9 or earlier.  Works on Qt 5.9.1 or later.
    viewer.engine()->addImportPath("qrc://");     // Works on Qt 5.9 or earlier.  FAILS on Qt 5.9.1 or later.
    viewer.engine()->addImportPath("qrc:///");    // Works on Qt 5.9 or earlier.  Works on Qt 5.9.1 or later.
    

    Guess which form I was using in the app which stopped working between Qt5.7 and 5.9.x?

    To be honest I've never been too clear what the right number of slashes to use in URIs is. But clearly something changed about how two are handled. (And actually now I look at https://en.wikipedia.org/wiki/Uniform_Resource_Identifier it seems only one or three would be comply with the syntax there; whether the initial "extra" two are required apparently depends on the scheme... which begs the question whether qrc URIs should really always be qrc:/// or whether a simple qrc:/ will do?)

    Trivial testcase demonstrating the issue can be found here: https://bitbucket.org/timday/qtissue002 (the Qt version is set in MAKE-linux or MAKE-mac; the addImportPath is in main.cpp).

    Will mark this solved when I've confirmed the fix applies to the main app too...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.