Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QML_ELEMENT support #99

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

arBmind
Copy link
Collaborator

@arBmind arBmind commented Jan 1, 2023

After Meeting C++ 2022 I got inspired to start a new experiment to get QML_ELEMENT support for Verdigris. #83

QML_ELEMENT and friends macros were introduced with Qt 5.15 . Why do we need it?

  • lifts the need to do qmlRegisterType for each type.
  • allows tooling (like QtCreator) to build support for custom QML types.

We have two challenges that are solved somewhat with this PR:

  1. Generate a metatypes.json by compiling just C++ code.
    • Generate a string of proper JSON with C++20 code.
    • This string is stored in a special binary section in the object files. (Works with MSVC and GCC/Clang)
  2. Use the build system to call a tool to extract the JSON and use it for qttyperegistrar.
    • Extract the JSON from the object files. (Works for MSVC and GCC on Linux)
    • CMake projects can use an extra object library target as a source for the extractor, and inject into the Qt CMake functions, by providing the right target properties.
    • Qbs projects require a patch to get something similar to object library which is then used as source for the extract tool and generates files tagged similar to those generated by the moc tool.

Extra benefits:

  • Added full CMake build system support.

Known Limitations/TODOs:

  • MacOS support is missing. Extractor tool may need to get support for mac specific object files.
  • The current approach for QML_ELEMENT won't work with templated objects.

Side note: This PR merges to the new develop branch. Which is basically what I proposed in #95.

@arBmind arBmind mentioned this pull request Jan 1, 2023
@arBmind arBmind changed the title [WIP] QML_ELEMENT support (for Verdigris 2.0) Add QML_ELEMENT support Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant