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. "is not a type" error when importing custom qml from resource
Forum Update on Monday, May 27th 2025

"is not a type" error when importing custom qml from resource

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qml import
7 Posts 4 Posters 4.8k 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.
  • A Offline
    A Offline
    Alp Hancioglu
    wrote on 30 Jul 2018, 09:10 last edited by
    #1

    I have the following directory structure:

    ui/
      |- resources.qrc
      |- qml/
          |- main_window.qml
          |- ControlUnitListPresenter.qml
    

    resources.qrc contents:

    <RCC>
      <qresource prefix="/">
        <file>qml/ControlUnitListPresenter.qml</file>
        <file>qml/main_window.qml</file>
      </qresource>
    </RCC>
    

    main_window.qml contents:

    import QtQuick 2.11
    import QtQuick.Controls 1.4
    import QtQuick.Layouts 1.11
    
    ApplicationWindow {
      visible: true
      visibility: "Maximized"
    
      menuBar: MenuBar {
        Menu {
          title: "File"
          MenuItem { text: "Open" }
          MenuItem { text: "Save" }
        }
      }
    
      ControlUnitListPresenter {
      }
    }
    

    main.cpp contents:

    int main(int argc, char **argv)
    {
      QGuiApplication app(argc, argv);
    
      QQmlApplicationEngine engine;
      engine.load(":/qml/main_window.qml");
    
      return app.exec();
    }
    

    When I run the application I get:

    QQmlApplicationEngine failed to load component
    file::/qml/main_window.qml:22 ControlUnitListPresenter is not a type
    

    I don't think I need an import statement because they are in the same directory.

    R 1 Reply Last reply 30 Jul 2018, 10:46
    0
    • A Alp Hancioglu
      30 Jul 2018, 09:10

      I have the following directory structure:

      ui/
        |- resources.qrc
        |- qml/
            |- main_window.qml
            |- ControlUnitListPresenter.qml
      

      resources.qrc contents:

      <RCC>
        <qresource prefix="/">
          <file>qml/ControlUnitListPresenter.qml</file>
          <file>qml/main_window.qml</file>
        </qresource>
      </RCC>
      

      main_window.qml contents:

      import QtQuick 2.11
      import QtQuick.Controls 1.4
      import QtQuick.Layouts 1.11
      
      ApplicationWindow {
        visible: true
        visibility: "Maximized"
      
        menuBar: MenuBar {
          Menu {
            title: "File"
            MenuItem { text: "Open" }
            MenuItem { text: "Save" }
          }
        }
      
        ControlUnitListPresenter {
        }
      }
      

      main.cpp contents:

      int main(int argc, char **argv)
      {
        QGuiApplication app(argc, argv);
      
        QQmlApplicationEngine engine;
        engine.load(":/qml/main_window.qml");
      
        return app.exec();
      }
      

      When I run the application I get:

      QQmlApplicationEngine failed to load component
      file::/qml/main_window.qml:22 ControlUnitListPresenter is not a type
      

      I don't think I need an import statement because they are in the same directory.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 30 Jul 2018, 10:46 last edited by
      #2

      @Alp-Hancioglu said in "is not a type" error when importing custom qml from resource:

      I don't think I need an import statement because they are in the same directory.

      not that i am aware of, try add import "."

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alp Hancioglu
        wrote on 30 Jul 2018, 10:50 last edited by Alp Hancioglu
        #3
        import "."
        

        gave me

        QQmlApplicationEngine failed to load component
        file::/qml/main_window.qml:4 import "." has no qmldir and no namespace
        

        By the way I am using meson as build system instead of qmake if it makes any difference. It shouldn't because meson also uses rcc.

        R J 2 Replies Last reply 30 Jul 2018, 10:55
        0
        • A Alp Hancioglu
          30 Jul 2018, 10:50
          import "."
          

          gave me

          QQmlApplicationEngine failed to load component
          file::/qml/main_window.qml:4 import "." has no qmldir and no namespace
          

          By the way I am using meson as build system instead of qmake if it makes any difference. It shouldn't because meson also uses rcc.

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 30 Jul 2018, 10:55 last edited by
          #4

          @Alp-Hancioglu
          strange. import "." normally doesn't require a qmldir file.

          Try to load load your ui with an QUrl instead of a filepath:

          engine.load( QUrl("qrc:/qml/main_window.qml") );
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • A Alp Hancioglu
            30 Jul 2018, 10:50
            import "."
            

            gave me

            QQmlApplicationEngine failed to load component
            file::/qml/main_window.qml:4 import "." has no qmldir and no namespace
            

            By the way I am using meson as build system instead of qmake if it makes any difference. It shouldn't because meson also uses rcc.

            J Online
            J Online
            J.Hilk
            Moderators
            wrote on 30 Jul 2018, 10:55 last edited by
            #5

            @Alp-Hancioglu said in "is not a type" error when importing custom qml from resource:

            meson

            I don't have experience with meson, but with qmake, you'll have to rerun qmake after adding a qml file to the ressource file. Because the ressource file is not recreated each time you add or remove components.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Alp Hancioglu
              wrote on 30 Jul 2018, 11:47 last edited by
              #6

              @raven-worx

              engine.load( QUrl("qrc:/qml/main_window.qml") );
              

              works. There is no need for import. Thanks.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                davidzoe
                wrote on 19 Sept 2022, 08:48 last edited by
                #7

                I have the same thing as you, there are 2 solutions, 1 is to lower the qt version below 6, the second is to use cmake to compile, it will be successful

                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