QQmlApplicationEngine failed to load component
-
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:
And finally the infamous error:
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!!
-
Your executable is not linked to your QML module.
-
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:
And finally the infamous error:
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!!
@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?