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. qt6 qt creator qml module not found
Forum Update on Monday, May 27th 2025

qt6 qt creator qml module not found

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 419 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
    anthoy
    wrote on last edited by
    #1

    I create a project for test, But there are some problems when using qmldir, when using qmldir, the program can run normally,
    but qt creator will have a red underline to prompt qml module not found.
    I have been looking for a long time and have not found a solution
    Here's my profile:

    project

    │  .gitignore
    │  CMakeLists.txt
    │  CMakeLists.txt.user
    │  readme.md
    │  resources.qrc
    └─src
        │  main.cpp
        │  Main.qml
        │
        └─test
                qmldir
                Test.qml
    

    cmakelists.txt

    cmake_minimum_required(VERSION 3.16)
    
    project(Station VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_AUTORCC ON)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(Qt6 6.4 REQUIRED COMPONENTS Quick)
    
    qt_standard_project_setup()
    
    qt_add_executable(appStation
        src/main.cpp
    )
    
    # https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html
    # https://www.qt.io/blog/whats-new-for-qml-modules-in-6.5#commento
    if(QT_KNOWN_POLICY_QTP0001)
        qt_policy(SET QTP0001 OLD)
    endif()
    
    qt_add_qml_module(appStation
        URI Station
        VERSION 1.0
        RESOURCES resources.qrc
    )
    
    list(APPEND QML_IMPORT_PATH "${PROJECT_SOURCE_DIR}/src/test")
    list(REMOVE_DUPLICATES QML_IMPORT_PATH)
    message("QML_IMPORT_PATH: ${QML_IMPORT_PATH}")
    set(QML_IMPORT_PATH ${QML_IMPORT_PATH}
        CACHE STRING "qml import paths"
        FORCE
    )
    
    # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
    # If you are developing for iOS or macOS you should consider setting an
    # explicit, fixed bundle identifier manually though.
    set_target_properties(appStation PROPERTIES
    #    MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appStation
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    target_link_libraries(appStation
        PRIVATE Qt6::Quick
    )
    
    include(GNUInstallDirs)
    install(TARGETS appStation
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    

    qrc

    <RCC>
        <qresource prefix="/qml">
            <file alias="Main.qml">src/Main.qml</file>
            <file alias="Station/Test/qmldir">src/test/qmldir</file>
            <file alias="Station/Test/Test.qml">src/test/Test.qml</file>
        </qresource>
    </RCC>
    

    qmldir

    Module Station.Test
    Test                1.0             Test.qml
    

    main

    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        const QUrl url(QStringLiteral("qrc:/qml/Main.qml"));
        QObject::connect(
            &engine,
            &QQmlApplicationEngine::objectCreationFailed,
            &app,
            []() { QCoreApplication::exit(-1); },
            Qt::QueuedConnection);
        engine.addImportPath("qrc:/qml");
        engine.load(url);
    
        return app.exec();
    }
    
    import QtQuick
    
    import Station.Test     1.0
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Test {
            anchors.centerIn:parent
        }
    }
    

    I dont know why it can run, but Qt Creator say qml module not found

    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