The same Qt6 Cmake project, MacOS build is OK, Win Display error: No such file or directory
Unsolved
Qt 6
-
Hello, everyone. I am new to qt qml, I came across one problem:
- I work with windows10\11 and MacOS
- I created a default project using QT6.2 and CMake
- by default, The main.cpp file and main.qml files in the same project directory, everything is OK on both systems build
- 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?