Hasty Briefsbeta

C++26 Reflection loves QRangeModel

18 days ago
  • #C++26
  • #Reflection
  • #Qt
  • The Qt Company's R&D organization started the year with a Hackathon, allowing employees to work on projects of their choice.
  • Volker Hilsheimer explored C++26 reflection features, specifically focusing on QRangeModel to represent plain C++ classes as models for Qt Quick's item views.
  • The goal was to enable a list of structs like `Entry` to be represented as a two-column table model without requiring metaobject or tuple-protocol boilerplate.
  • C++26 introduces new features like reflections and annotations, which were used to dynamically access and modify class members without moc-generated code.
  • The implementation involved using GCC's reflection branch and required building a custom Qt version to test the new features.
  • Specializations for `row_traits` and `item_traits` were created to handle aggregate types and annotated classes, enabling dynamic property access.
  • The project successfully demonstrated reading and writing to class members using C++26's reflection and splice operators.
  • Future possibilities include using C++26 reflections to replace moc, though challenges like handling signals and slots remain.
  • Feedback was solicited on QRangeModel usage and the potential benefits of upgrading to C++26 for reflection capabilities.