mesonbuild/meson

qt6.qml_module(): forward Qt6's metatype .json files to qmltyperegistrar

Open

#15.801 aperta il 12 mag 2026

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)Python (1465 fork)batch import
enhancementgood first issuemodule:qt

Metriche repository

Star
 (4978 star)
Metriche merge PR
 (Merge medio 30g 19h) (63 PR mergiate in 30 g)

Descrizione

Hey,

This a follow-up on https://github.com/mesonbuild/meson/pull/13304#issuecomment-2555672257

Issue description

If one does this

git clone https://github.com/AdelKS/ZeGrapher.git
cd ZeGrapher
git checkout dd1273e
meson setup build && meson compile

One will see these warnings

Warning: datapoints.h:40: QQuickItem is used as base type but cannot be found.
Warning: graph.h:37: QQuickPaintedItem is used as base type but cannot be found.
Warning: graph.h:37: MathObjectDraw is used as base type but cannot be found.
Warning: highlighter.h:10: QSyntaxHighlighter is used as base type but cannot be found.
Warning: information.h:35: QObject is used as base type but cannot be found.
Warning: structures.h:79: QObject is used as base type but cannot be found.
Warning: updatecheck.h:9: QObject is used as base type but cannot be found.
Warning: appsettings.h:30: QObject is used as base type but cannot be found.
Warning: graphsettings.h:32: QObject is used as base type but cannot be found.
Warning: structures.h:115: QObject is used as base type but cannot be found.
Warning: animatedconstant.h:33: QObject is used as base type but cannot be found.
Warning: animationconductor.h:38: QObject is used as base type but cannot be found.
Warning: csvpreviewmodel.h:30: QAbstractTableModel is used as base type but cannot be found.
Warning: datatablemodel.h:32: QAbstractTableModel is used as base type but cannot be found.
Warning: graphrange.h:66: QObject is used as base type but cannot be found.
Warning: mathobject.h:37: QObject is used as base type but cannot be found.
Warning: mathworld.h:38: QAbstractListModel is used as base type but cannot be found.
Warning: plotstyle.h:33: QObject is used as base type but cannot be found.
Warning: stateful.h:32: QObject is used as base type but cannot be found.
Warning: graphrange.h:30: QObject is used as base type but cannot be found.
Warning: parametric.h:32: QObject is used as base type but cannot be found.

They don't affect the resulting binary or cause issues as far as I know, but it would be nice to not have them.

By looking at Github's runner logs on pipelines that bundle ZeGrapher, it happens on Linux (Qt installed with aqtinstall) and MacOS (Qt installed with homebrew), but not on Windows (Qt installed with Msys2): is this a packaging issue actually ?

Fix

To avoid these warnings, qml_module should iterate through the qt dependency modules it receives through its dependencies kwargs, for each module:

  1. Check if qt_libdir / qt6 / metatypes / qt6<module_name>_metatypes.json exists
  2. If it exists, add it to a string that is passed to --foreign-types= to qmltyperegistrar

The fix above can be fully implemented in downstream meson projects like this

fs = import('fs')
qt6 = import('qt6')

qt6_modules = [
  'Core',
  'Gui',
  'Widgets',
  'Network',
  'Svg',
  'Quick',
  'Qml',
  'QuickWidgets',
  'QmlIntegration',
  'ShaderTools'
]

qt6_dep = dependency('qt6',
  version: '>=6.10',
  modules: qt6_modules
)

qt6_metatypes_dir = qt6_dep.get_variable(pkgconfig: 'libdir') / 'qt6' / 'metatypes'

qt6_foreign_metatypes = []
foreach qt6_mod: qt6_modules
  metatype_file_path = qt6_metatypes_dir / 'qt6' + qt6_mod.to_lower() + '_metatypes.json'
  if fs.exists(metatype_file_path)
    qt6_foreign_metatypes += [metatype_file_path]
  endif
endforeach

qml_mods = qt6.qml_module(
  'Foo',
  // ...
  dependencies: [qt6_dep],
  qmltyperegistrar_extra_arguments: ['--foreign-types=' + ','.join(qt6_foreign_metatypes)],
)
diff --git a/src/meson.build b/src/meson.build
index 2affd3c..68c91c2 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -135,24 +135,38 @@ foreach qmlcpp_file: qmlcpp_files
 endforeach
 
 qt6 = import('qt6')
+
+qt6_modules = [
+  'Core',
+  'Gui',
+  'Widgets',
+  'Network',
+  'Svg',
+  'Quick',
+  'Qml',
+  'QuickWidgets',
+  'QmlIntegration',
+  'ShaderTools'
+]
+
 qt6_dep = dependency('qt6',
   version: '>=6.10',
-  modules: [
-    'Core',
-    'Gui',
-    'Widgets',
-    'Network',
-    'Svg',
-    'Quick',
-    'Qml',
-    'QuickWidgets',
-    'QmlIntegration',
-    'ShaderTools'
-  ]
+  modules: qt6_modules
 )
 boost_dep = dependency('boost')
 zecalculator_dep = dependency('zecalculator')
 
+
+qt6_metatypes_dir = qt6_dep.get_variable(pkgconfig: 'libdir') / 'qt6' / 'metatypes'
+
+qt6_foreign_metatypes = []
+foreach qt6_mod: qt6_modules
+  metatype_file_path = qt6_metatypes_dir / 'qt6' + qt6_mod.to_lower() + '_metatypes.json'
+  if fs.exists(metatype_file_path)
+    qt6_foreign_metatypes += [metatype_file_path]
+  endif
+endforeach
+
 compiled_ressources = qt6.compile_resources(sources: files('../ressources.qrc'))
 
 # --- Qt RHI shader compilation -----------------------------------------------
@@ -205,6 +219,7 @@ qml_mods = qt6.qml_module(
   moc_headers: qmlcpp_files,
   include_directories: qmlcpp_inc_dirs,
   dependencies: [qt6_dep],
+  qmltyperegistrar_extra_arguments: ['--foreign-types=' + ','.join(qt6_foreign_metatypes)],
 )
 
 compiler = meson.get_compiler('cpp')

Guida contributor