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. Directory imports when using a QRC resource file with prefixes
Forum Update on Monday, May 27th 2025

Directory imports when using a QRC resource file with prefixes

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.9k 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.
  • MonomixM Offline
    MonomixM Offline
    Monomix
    wrote on last edited by Monomix
    #1

    We have an application that has quite a lot of different views and controls - to keep things tidy, we have the files in different directories, and reference files within the directory structure using relative paths. The files are included in our application using the resource system.

    This works with qmlscene and with the built application when there are no prefixes in the QRC file, but doesn't work in the application when prefixes are introduced. (Without prefixes, opening the QRC file in Creator shows a flat list of almost a hundred files - with prefixes, there's a folder structure, so the prefixes are nice to have.)

    A quick example:

    • MainApplicationWindow.qml,

      import "views"
      
      ApplicationWindow {
          SomeView {}
      } 
      

    Relative to MainApplicationWindow.qml, the file SomeView.qml is located at directory views/SomeView.qml.

    It works with the QRC entry

    <qresource prefix="/">
        <file>MainApplicationWindow.qml</file>
        <file>views/SomeView.qml</file>
    </qresource>
    

    but when the QRC entry is

    <qresource prefix="/">
        <file>MainApplicationWindow.qml</file>
    </qresource>
    <qresource prefix="/views">
        <file>views/SomeView.qml</file>
    </qresource>
    

    I get the runtime error "SomeView is not a type." Any ideas how to get this to work?

    p3c0P 1 Reply Last reply
    0
    • MonomixM Monomix

      We have an application that has quite a lot of different views and controls - to keep things tidy, we have the files in different directories, and reference files within the directory structure using relative paths. The files are included in our application using the resource system.

      This works with qmlscene and with the built application when there are no prefixes in the QRC file, but doesn't work in the application when prefixes are introduced. (Without prefixes, opening the QRC file in Creator shows a flat list of almost a hundred files - with prefixes, there's a folder structure, so the prefixes are nice to have.)

      A quick example:

      • MainApplicationWindow.qml,

        import "views"
        
        ApplicationWindow {
            SomeView {}
        } 
        

      Relative to MainApplicationWindow.qml, the file SomeView.qml is located at directory views/SomeView.qml.

      It works with the QRC entry

      <qresource prefix="/">
          <file>MainApplicationWindow.qml</file>
          <file>views/SomeView.qml</file>
      </qresource>
      

      but when the QRC entry is

      <qresource prefix="/">
          <file>MainApplicationWindow.qml</file>
      </qresource>
      <qresource prefix="/views">
          <file>views/SomeView.qml</file>
      </qresource>
      

      I get the runtime error "SomeView is not a type." Any ideas how to get this to work?

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @Monomix
      Just add prefix to the imported directory. i.e
      import "views/views"

      157

      1 Reply Last reply
      0
      • MonomixM Offline
        MonomixM Offline
        Monomix
        wrote on last edited by Monomix
        #3

        Thanks for the suggestion - it works now with the built application (albeit with problems caused by relative paths in the QML files in subfolders), but not with qmlscene ("views/views": no such directory). It'd be really nice to find a solution that works with both, and takes in both the need for a file structure with subfolders and a QRC file with prefixes...

        p3c0P 1 Reply Last reply
        0
        • MonomixM Monomix

          Thanks for the suggestion - it works now with the built application (albeit with problems caused by relative paths in the QML files in subfolders), but not with qmlscene ("views/views": no such directory). It'd be really nice to find a solution that works with both, and takes in both the need for a file structure with subfolders and a QRC file with prefixes...

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @Monomix Ok. But I'm not sure if resources work with qmlscene.

          157

          1 Reply Last reply
          0

          • Login

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