Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. The same Qt6 Cmake project, MacOS build is OK, Win Display error: No such file or directory

The same Qt6 Cmake project, MacOS build is OK, Win Display error: No such file or directory

Scheduled Pinned Locked Moved Unsolved Qt 6
1 Posts 1 Posters 458 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.
  • V Offline
    V Offline
    ViVi_Z
    wrote on last edited by
    #1

    Hello, everyone. I am new to qt qml, I came across one problem:

    1. I work with windows10\11 and MacOS
    2. I created a default project using QT6.2 and CMake
    3. by default, The main.cpp file and main.qml files in the same project directory, everything is OK on both systems build
    4. but, move the Main.Qml files into a subdirectory, like"Qml"folder, MacOS(Clang) build is OK!!!, Win(MinGW and MSVC) Display error message!!!:
      QQmlApplicationEngine failed to load component
      qrc:/Qml/main: No such file or directory
      QML debugging is enabled. Only use this in a safe environment

    5.This is my main.cpp:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    #include <QLocale>
    #include <QTranslator>
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        const QUrl url(u"qrc:/Qml/main.qml"_qs);
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        engine.load(url);
    
        return app.exec();
    }
    

    6.This is my ./CMakeLists.txt:

    cmake_minimum_required(VERSION 3.21.1)
    project(NodeEditor_Qt6 VERSION 0.1.0 LANGUAGES CXX)
    
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED True)
    
    
    set(CMAKE_AUTOMOC True)
    set(CMAKE_AUTOUIC True)
    set(CMAKE_AUTORCC True)
    
    find_package(Qt6 6.2 REQUIRED COMPONENTS Core Gui Qml Quick)
    
    qt_add_executable(
        appHello
        main.cpp
    )
    
    set_target_properties(appHello PROPERTIES
        MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    target_compile_definitions(appHello
        PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
    
    
    target_link_libraries(
        appHello
        PRIVATE
            appQml
    )
    
    target_link_libraries(
        appHello
        PRIVATE
            Qt6::Core
            Qt6::Gui
            Qt6::Qml
            Qt6::Quick
    )
    

    7.This is my Qml/CMakeLists.txt:

    find_package(Qt6 6.2 REQUIRED COMPONENTS Core Qml Quick)
    
    qt_add_qml_module(
        appQml 
        URI Qml
        VERSION 1.0   
        SHARED    
        QML_FILES    
            main.qml
    )
    

    can any please help?

    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