Debian Codegraph @

src/pappsomspp/core/js_qml/forwarding_includes/README

raw
1 Debugging Tip
2
3 Check if pappsoms_qmltyperegistrations.cpp includes your header:
4
5 #include "pappsomspp/processing/combiners/mzintegrationparams.h"
6
7 If not, that's the problem.
8
9 Indeed, it has the following include statement:
10
11 #if __has_include(<mzintegrationparams.h>)
12 # include <mzintegrationparams.h>
13 #endif
14
15
16 ChatGPT said:
17
18 Ah, that’s the crux of the problem.
19
20 The line:
21
22 #if __has_include(<mzintegrationparams.h>)
23 # include <mzintegrationparams.h>
24 #endif
25
26 in the auto-generated pappsoms_qmltyperegistrations.cpp only includes the header if it can be found as <mzintegrationparams.h> in the global include paths β€” i.e., not using a relative or subdirectory-prefixed path like pappsomspp/processing/combiners/mzintegrationparams.h.
27 πŸ” Why it fails
28
29 In your setup, the header is probably only available as:
30
31 #include "pappsomspp/processing/combiners/mzintegrationparams.h"
32
33 and not as:
34
35 #include <mzintegrationparams.h>
36
37 So __has_include(<mzintegrationparams.h>) returns false, and your class is never included into the generated file β€” meaning pappso::MzIntegrationParams is undefined.
38 βœ… Solution Options
39 βœ… Option 1: Add an #include path
40
41 Make sure the directory containing mzintegrationparams.h is added to your public include directories:
42
43 target_include_directories(PappsoMS PUBLIC
44 ${CMAKE_CURRENT_SOURCE_DIR}/pappsomspp/processing/combiners
45 )
46
47 Then #include <mzintegrationparams.h> will resolve correctly during auto-generation.
48
49 βœ… Option 2: Rename header or create a forwarding header
50
51 Create a file at pappsomspp/processing/combiners/mzintegrationparams.h that’s publicly visible and easy to include. Or, even better, put a symlink or forwarding header in a top-level include directory:
52
53 // in include/mzintegrationparams.h
54 #include "pappsomspp/processing/combiners/mzintegrationparams.h"
55
56 Then ensure include/ is in your public include directories.
57 🧹 Also Recommended
58
59 Run a clean rebuild after modifying include paths or QML module definitions. Qt code generation can cache outdated assumptions.
60 βœ… Summary Fix Plan
61
62 To fix your issue:
63
64 Add this to your CMake target:
65
66 target_include_directories(PappsoMS PUBLIC
67 ${CMAKE_CURRENT_SOURCE_DIR}/pappsomspp/processing/combiners
68 )
69
70 (Optional but safer) Change your header guard or filename to match <mzintegrationparams.h> (or create a forwarding header).
71
72 Run rm -rf build-area && cmake ... && make.
73
74 Let me know if you'd like help creating a forwarding header or adjusting the CMake include paths!
75 You said:
76 This is bad design ! when including internal header files in a given projet the bracket notation is discouraged, no ?
77 ChatGPT said:
78
79 You're absolutely right β€” using #include <...> for internal project headers is not good design. That notation is traditionally reserved for external, system, or library headers. For internal headers, the recommended practice is:
80
81 #include "relative/path/to/header.h"
82
83 πŸ’‘ So why is Qt doing this?
84
85 Qt’s qt_add_qml_module() generates code that uses:
86
87 #if __has_include(<mzintegrationparams.h>)
88 # include <mzintegrationparams.h>
89 #endif
90
91 This is a generic mechanism to auto-include any QML-annotated class headers by filename only, assuming the header is available in the compiler's include path β€” even if it's not great from a software architecture point of view.
92
93 So yes, this is a design compromise Qt makes to support auto-registration of QML types. The underlying logic is:
94
95 Qt scans for QML-exported C++ types via QML_ELEMENT, etc.
96
97 It generates registration code and tries to include the header by guessing the filename.
98
99 To avoid hardcoding paths, it uses __has_include(<name.h>) and assumes the project has exposed the header in the public include path.
100
101 βœ… Correct Design Approach for You
102
103 You can preserve good internal design and still make this work without polluting your project with bad #include <...> style.
104 βœ… Recommended Fix with Correct Design
105
106 Keep your internal includes clean:
107
108 Keep using "pappsomspp/processing/combiners/mzintegrationparams.h" in your own code.
109
110 Do not switch to <mzintegrationparams.h> in your project.
111
112 Work around Qt’s generator expectations:
113
114 Add a forwarding header for the specific classes you export to QML, and place it in an internal "qml_export" directory:
115
116 include/pappsoqml/mzintegrationparams.h
117
118 with contents:
119
120 #pragma once
121 #include "pappsomspp/processing/combiners/mzintegrationparams.h"
122
123 Add this directory to your include paths for the Qt-generated code:
124
125 target_include_directories(PappsoMS PUBLIC
126 ${CMAKE_CURRENT_SOURCE_DIR}/include/pappsoqml
127 )
128
129 This satisfies the generator's <mzintegrationparams.h> lookup without polluting your internal logic or exposing deeply nested paths.
130
131 (Optional but clean) Use CMake's PUBLIC_HEADERS if available to declare headers that should be "publicly visible", and map those into a clean public include structure.
132
133 🧡 TL;DR
134
135 Yes, Qt’s generated #include <...> for internal headers is poor design β€” but you can work around it cleanly by:
136
137 Keeping your internal includes with "...".
138
139 Providing Qt a shim/forward header in a separate include directory just for QML exports.
140
141 Avoiding the need to expose all your internal directories via target_include_directories.
142
143 Let me know if you'd like a snippet showing exactly how to structure the forwarding headers!
144 You said:
145 Waouw, very good that worked !
146 ChatGPT said:
147
148 That's fantastic to hear β€” well done! πŸŽ‰
149
150 By keeping your internal headers clean and using a dedicated forwarding header just for Qt's generator, you've got the best of both worlds:
151
152 βœ… Clean project architecture
153 βœ… Working QML integration
154 βœ… No need to misuse angle brackets for internal includes
155
156 If you end up registering more classes to QML, you can keep dropping lightweight forwarding headers in your include/pappsoqml/ folder β€” it's a small maintenance cost for a very clean separation.
157
158 If you need help automating that or managing module versioning, I'm here. Happy coding! πŸš€