Using a macro to create QObject derived classes

前端 未结 3 1133
执笔经年
执笔经年 2021-01-06 01:36

I\'m trying to simplify (i.e. get rid of loads of boilerplate code) the creation of QObject wrapper classes that forward property access of other QObject<

3条回答
  •  时光说笑
    2021-01-06 02:34

    The vagaries of moc aside, your wrapper is not thread-safe. The property getter is not invoked from the correct thread. So I don't see any point of the wrapper. You might as well use the wrapped class directly from QML, not the wrapper.

    To be thread-safe, your wrapper should be caching the wrapped property's value, so that the reads always happen from the local copy.

    At that point you might as well write a fully dynamic wrapper that thread-safely forwards all properties from the wrapped object. Using the metaobject system you can generate everything on the fly - the copies of the property values, etc. As far as properties go, you can copy the entire binary descriptor as your wrapper pretends to have the same properties.

提交回复
热议问题