No matter what, QT Creator refuses to 'see' the included qml file
-
I have a very simple barebone project that just opens a window with nothing in it.
The problem is: It just doesn't want to import the User model qml file. The editor does without any problem. But when I start to built the project, i get these two message:
QQmlApplicationEngine failed to load component
qrc:/ui/main.qml:4:1: "../models/user.qml": no such directory qrc:/ui/main.qml: 4
Why can CT Creator editor find the files without any problem, but the compiler is lost?
/qml.qrc
<RCC> <qresource prefix="/"> <file>ui/main.qml</file> <file>models/UserModel.qml</file> </qresource> </RCC>
/models/UserModel.qml
import QtQuick 2.15 Item { }
/ui/main.qml
import QtQuick 2.15 import QtQuick.Window 2.15 import "qrc:/models/UserModel.qml" as User //import "../models/UserModel.qml" as User // Also doesn't work! // The main screen ApplicationWindow { id: window width: 800 height: 600 visible: true title: qsTr("Hello World") color: "#1e2433" //flags: Qt.Window }
/CMakeLists.txt
cmake_minimum_required(VERSION 3.14) project(KAuthenticator VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick LinguistTools) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick LinguistTools) set(TS_FILES KAuthenticator_en_US.ts) set(PROJECT_SOURCES qml.qrc src/main.cpp i18n/${TS_FILES} ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(KAuthenticator MANUAL_FINALIZATION ${PROJECT_SOURCES} ) # Define target properties for Android with Qt 6 as: # set_property(TARGET KAuthenticator APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # ${CMAKE_CURRENT_SOURCE_DIR}/android) # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) else() if(ANDROID) add_library(KAuthenticator SHARED ${PROJECT_SOURCES} ) # Define properties for Android with Qt 5 after find_package() calls as: # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") else() add_executable(KAuthenticator ${PROJECT_SOURCES} ) endif() qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) endif() target_link_libraries(KAuthenticator PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick) set_target_properties(KAuthenticator 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 ) install(TARGETS KAuthenticator BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) if(QT_VERSION_MAJOR EQUAL 6) qt_import_qml_plugins(KAuthenticator) qt_finalize_executable(KAuthenticator) endif()
-
@niquedegraaff said in No matter what, QT Creator refuses to 'see' the included qml file:
import "qrc:/models/UserModel.qml" as User
I don't think this is valid. See e.g. https://doc.qt.io/qt-6/qtqml-syntax-imports.html#import-types ; I think you want to import a directory here.
-
@niquedegraaff the path of your ../models/user.qml may not be used properly.
find the file
qrc_qml.cpp
in the build dir something like build/KAuthenticator_autogen/3YJK5W5UP7
and open it in an editor. Scroll all way to the end and check the path definition for it in
static const unsigned char qt_resource_struct[] ={
}.
Use that path in your code. -
@niquedegraaff said in No matter what, QT Creator refuses to 'see' the included qml file:
import "qrc:/models/UserModel.qml" as User
I don't think this is valid. See e.g. https://doc.qt.io/qt-6/qtqml-syntax-imports.html#import-types ; I think you want to import a directory here.
-