Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Cannot import directory in resources

Cannot import directory in resources

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 4.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xylosper
    wrote on 12 Jun 2017, 12:20 last edited by
    #1

    I have a qrc file which contains:

    /qml/main.qml
    /qml/scene/CityScene.qml
    

    When I write import "scene" in main.qml, it prints:

    QQmlApplicationEngine failed to load component
    file::/qml/main.qml:19 import "scene" has no qmldir and no namespace
    

    If I change import "scene" to import "qrc:/qml/scene", it just works fine.
    But this is very annoying because whenever importing directory, it makes me write full absolute directory path.
    Futhermore, I'm using qrc file only for releasing and I don't use qrc file during developing/debugging.
    If I have to write always absolute path for QML file in resources, I have to write two sets of QML file which differ for only import statements.

    How can I make import "scene" work with QML file in qrc file here?

    FYI, I've tried to add /qml/scene/qmldir file but it didn't work.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 12 Jun 2017, 13:03 last edited by sierdzio 6 Dec 2017, 13:04
      #2

      QML engine assumes the loading source base on how you call QQmlEngine::load(). If you use QRC there, it will be used for all import statements in QML, too. If you use relative path in load(), it will use relative paths in QML as well. If you use shadow building (the default), it means that it will look for "scene" directory in your build dir.

      Hope it helps :-) There is also a way to disable QRC temporarily, I've described it here: link.

      I do recommend, however, to use QRC both for production and development - you'll have no issues at all :-)

      (Z(:^

      1 Reply Last reply
      1
      • S Offline
        S Offline
        stephen.m.dangelo
        wrote on 11 Oct 2017, 15:48 last edited by
        #3

        Hello, I'm having a similar issue, except I would like to reference my QRC imports via an absolute path, as they are spread out amongst many plugins. This is with Qt 5.9.1.

        e.g. In the example given here, it would be:

        import "/scene"
        

        I'm porting a large project from Qt4, where this worked just fine. I also had this running with an older version of Qt5 (can't quite remember which one).

        I know I can replace all of my imports with import "qrc:/scene", but I'd like to avoid that, as I'm then tied to the QRC system.

        Is there any possible workaround, or has this functionality just been completely removed?

        S 1 Reply Last reply 12 Oct 2017, 05:36
        0
        • S stephen.m.dangelo
          11 Oct 2017, 15:48

          Hello, I'm having a similar issue, except I would like to reference my QRC imports via an absolute path, as they are spread out amongst many plugins. This is with Qt 5.9.1.

          e.g. In the example given here, it would be:

          import "/scene"
          

          I'm porting a large project from Qt4, where this worked just fine. I also had this running with an older version of Qt5 (can't quite remember which one).

          I know I can replace all of my imports with import "qrc:/scene", but I'd like to avoid that, as I'm then tied to the QRC system.

          Is there any possible workaround, or has this functionality just been completely removed?

          S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 12 Oct 2017, 05:36 last edited by
          #4

          @stephen.m.dangelo said in Cannot import directory in resources:

          I know I can replace all of my imports with import "qrc:/scene", but I'd like to avoid that, as I'm then tied to the QRC system.
          Is there any possible workaround, or has this functionality just been completely removed?

          Use QRC to load your main.qml. Then all files inside main.qml will default to QRC as well and you will be able to use import "scene".

          (Z(:^

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved