Precompiling QML. Can't find modules error
-
Hello,
So as some context to the problem, I would like to hide the QML source code whilst meeting LGPL requirements with dynamic linking and it seems like the best strategy for this is to precompile the QML
From what I understand, to precompile QML, I need to add "ENABLE_TYPE_COMPILER" to main project qt_add_qml_module CmakeLists.txt file
https://doc.qt.io/qt-6/qtqml-qml-type-compiler.html
The problem I'm having though is that the moment I add "ENABLE_TYPE_COMPILER", I receive an error that it can't find the modules. Before I used modules, I had include file path directories for the QML components and had a similar error for this. Like it not being able to find stuff
Error: Path/Main.qml:8:1: Warnings occurred while importing module "NameOfModule": [import] import NameOfModule 1.0 ^^^^^^ --- Error: Failed to import NameOfModule. Are your import paths set up properly? [import] ---
Does anybody have experience with precompiling QML for the LGPL version of Qt (so I'm NOT able to use qmlsc, "which is a part of the commercial-only add-on Qt Quick Compiler Extensions."
https://doc.qt.io/qt-6/qtqml-qml-script-compiler.html
But AM able to use qmltc and qmlcachegen
https://doc.qt.io/qt-6/qtqml-qml-type-compiler.html
https://doc.qt.io/qt-6/qtqml-tool-qmlcachegen.html)?Perhaps you would know why it can find the module without ENABLE_TYPE_COMPILER but not with it. I mean if there's any projects that have done this even a GitHub link would be helpful to see if there's anything they might have had to do to make precompiling QML work.
In the main project Cmake file, I have all the things that I'd expect would be sufficient since it works with this without ENABLE_TYPE_COMPILER included in qt_add_qml_module
# Making our main program module accessible add_subdirectory(import/qml_module/NameOfModule)
set_property(TARGET appAppName_lib PROPERTY QML_IMPORT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/import/qml_module")
Then in the QML file itself, I have what we'd also expect to see
import NameOfModule 1.0
-
Okay for debugging purposes, I realized I could just use ENABLE_TYPE_COMPILER on the single module only and try to debug it
For one of my pure QML only text modules, it complains
This is my QML file BodyTextBase
import QtQuick import QtQuick.Layouts Text { readonly property font bodyTextFont: Qt.font({ "family": "Helvetica", "weight": Font.Normal, "italic": false, "pointSize": 16 }) readonly property color bodyTextFontColor: "black" font: bodyTextFont color: bodyTextFontColor wrapMode: Text.Wrap Layout.fillWidth: true }
This was the Cmake file for this child module
# File: import/qml_module/TextModule/CMakeLists.txt # Define the static library for the QML module qt_add_library(text_module STATIC) set_target_properties(text_module PROPERTIES AUTOMOC ON) target_link_libraries(text_module PRIVATE Qt6::Quick ) list(APPEND MODULE_QML_FILES BodyTextBase.qml ClickableLinkBase.qml Header1Base.qml Header2Base.qml Header3Base.qml Header4Base.qml Header5Base.qml Header6Base.qml ProgramTitleBase.qml ) # Define the QML module qt_add_qml_module(text_module URI TextModule VERSION 1.0 RESOURCE_PREFIX / ENABLE_TYPE_COMPILER QML_FILES ${MODULE_QML_FILES} )
It can't find some stuff from the auto-generated code
Issues I see
ChatGPT summary of the the warnings
### Errors in the `TextModule` build process: 1. **Missing Header Files:** Several errors are caused by missing files. The following files cannot be found: - `private/qquickevents_p_p.h` - `private/qquicklayout_p.h` - `private/qquickcolorgroup_p.h` 2. **Undeclared Identifiers:** In the following files, there are instances of undeclared identifiers: - `QQuickText`: This identifier is used but not declared in `bodytextbase.h`. - `QQuickLayoutAttached`: The error suggests this might be a typo and should be `QQuickWindowAttached`. 3. **Expected Class Name:** In `bodytextbase.h`, there's an issue where the compiler expects a class name, but something else is provided, resulting in an error. 4. **Build Stopped:** The build was stopped by `ninja` due to the errors encountered during compilation. --- These issues suggest that certain required Qt internal files are missing, and there are some coding or configuration issues related to undeclared or mistyped identifiers. You may need to check the configuration of your Qt environment, verify that all necessary Qt modules are included, and review the mentioned source files for the correct usage of identifiers and header files.