[Development] Request for early MOC support for C++20 Modules

Mathias Hasselmann mathias at taschenorakel.de
Wed Dec 20 00:11:18 CET 2023


Am 16.12.2023 um 09:21 schrieb apoenitz:
> I haven't tried yet, but I have the gut feeling that one should be able
> to get away with

Seems your gut feeling is right. Did a little experiment[1], and ended 
up with this:

class  MyObject  :public  Object<MyObject, QObject>
{
     M_OBJECT

public:
     using  Object::Object;

     void  modifyNotifying()
     {
         notifying =u"I have been changed per method"_s;
     }

     Property<n(), QString>          constant =u"I am constant"_s;
     Property<n(), QString, Notify> notifying =u"I am observing"_s;
     Property<n(), QString,  Write>  writable =u"I am modifiable"_s;

     Setter<QString> setWritable = &writable;

     static  constexpr  Signal<&MObject::notifying> notifyingChanged = {};
     static  constexpr  Signal<&MObject::writable> writableChanged = {};
};

Plus this tiny bit of boilerplate:

template<>
std::vector<MyObject::MetaProperty> MyObject::MetaObject::makeProperties()
{
     return {
         {"constant",    &null()->constant},     // FIXME: with some 
additional effort
         {"notifying",   &null()->notifying},    // &MObject::constant 
should be possible
         {"writable",    &null()->writable},
     };
}

M_OBJECT_IMPLEMENTATION(MObject, constant, notifying, writable)

Grab it from: https://github.com/hasselmm/PropertyExperiment

Warning: There will be dragons! It's just a proof of concept with 
terrible shortcuts,
not even remotely production quality.

Ciao
Mathias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20231220/97e6db31/attachment.htm>


More information about the Development mailing list