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. QQmlApplicationEngine failed to load component
Forum Updated to NodeBB v4.3 + New Features

QQmlApplicationEngine failed to load component

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 238 Views 1 Watching
  • 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.
  • I Offline
    I Offline
    imxande
    wrote on 19 Jun 2025, 07:47 last edited by
    #1

    Hi fam,

    So I have encounted a problem for a particular personal project that I am setting up. Basically, this has never happened in other projects when I try to load QML. I have always done it this way and QQmlApplicationEngine always loads the module but today is a no no. Here is what I got also far, basic setup:
    This is my main.cpp file:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QDebug>
    
    int main(int argc, char *argv[]) {
      // create application
      QGuiApplication app(argc, argv);
    
      // engine
      QQmlApplicationEngine engine;
    
      qDebug() << "Import paths:" << engine.importPathList();
    
      // load QML
      engine.loadFromModule("smartlights", "Main");
    
      return app.exec();
    }
    

    This is my cmake file:

    cmake_minimum_required(VERSION 3.28)
    
    project(nitenite VERSION 1.0.0 LANGUAGES CXX)
    
    find_package(Qt6 REQUIRED COMPONENTS Quick)
    
    qt_standard_project_setup(REQUIRES 6.8)
    
    
    set(CMAKE_STANDARD_CXX 20)
    set(CMAKE_STANDARD_CXX_REQUIRED ON)
    
    qt_add_executable(${PROJECT_NAME}
      src/main.cpp
    )
    
    qt_add_qml_module(smartLightsModule
      URI smartlights
      VERSION 1.0
      QML_FILES qml/smartlights/Main.qml
    )
    target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Quick)
    

    Here simplified file structure:
    f3256e2d-d101-41bd-adbe-d07201dca639-image.png

    And finally the infamous error:
    d50c37f6-789d-47db-9ac2-be2f33de8b43-image.png

    First time experiencing this error, I have always load QML into this type of application this way, and it always works.
    Note that if I add engine.addImportPath("qt/qml") to my main.cpp file the engine finds the module but I never had to do this before and want to understand what is really happening.

    In any case thank you all in advance, please help!!

    J 1 Reply Last reply 20 Jun 2025, 00:35
    0
    • G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 19 Jun 2025, 08:29 last edited by
      #2

      Your executable is not linked to your QML module.

      1 Reply Last reply
      4
      • I imxande
        19 Jun 2025, 07:47

        Hi fam,

        So I have encounted a problem for a particular personal project that I am setting up. Basically, this has never happened in other projects when I try to load QML. I have always done it this way and QQmlApplicationEngine always loads the module but today is a no no. Here is what I got also far, basic setup:
        This is my main.cpp file:

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        #include <QDebug>
        
        int main(int argc, char *argv[]) {
          // create application
          QGuiApplication app(argc, argv);
        
          // engine
          QQmlApplicationEngine engine;
        
          qDebug() << "Import paths:" << engine.importPathList();
        
          // load QML
          engine.loadFromModule("smartlights", "Main");
        
          return app.exec();
        }
        

        This is my cmake file:

        cmake_minimum_required(VERSION 3.28)
        
        project(nitenite VERSION 1.0.0 LANGUAGES CXX)
        
        find_package(Qt6 REQUIRED COMPONENTS Quick)
        
        qt_standard_project_setup(REQUIRES 6.8)
        
        
        set(CMAKE_STANDARD_CXX 20)
        set(CMAKE_STANDARD_CXX_REQUIRED ON)
        
        qt_add_executable(${PROJECT_NAME}
          src/main.cpp
        )
        
        qt_add_qml_module(smartLightsModule
          URI smartlights
          VERSION 1.0
          QML_FILES qml/smartlights/Main.qml
        )
        target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Quick)
        

        Here simplified file structure:
        f3256e2d-d101-41bd-adbe-d07201dca639-image.png

        And finally the infamous error:
        d50c37f6-789d-47db-9ac2-be2f33de8b43-image.png

        First time experiencing this error, I have always load QML into this type of application this way, and it always works.
        Note that if I add engine.addImportPath("qt/qml") to my main.cpp file the engine finds the module but I never had to do this before and want to understand what is really happening.

        In any case thank you all in advance, please help!!

        J Offline
        J Offline
        JKSH
        Moderators
        wrote on 20 Jun 2025, 00:35 last edited by JKSH
        #3

        @imxande said in QQmlApplicationEngine failed to load component:

        want to understand what is really happening.

        One way to start doing this is to inspect your embedded resources:

        QDirIterator qrc(":", QDirIterator::Subdirectories);
        while(qrc.hasNext())
            qDebug() << qrc.next();
        

        Note that if I add engine.addImportPath("qt/qml") to my main.cpp file the engine finds the module

        What does engine.importPathList() produce after you do that?

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        2

        1/3

        19 Jun 2025, 07:47

        • Login

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