On 21/03/2018 18:23, Marc-André Lureau wrote:
>>
>> Here, QObjectCommon is never used outside of qobject.h; all existing code
>> continues to uwe QObject *.  But the conversion from QString* or QObject *
>> to QObjectCommon * is trivial (&obj->base), and the conversion from
>> QObjectCommon * to the public QObject * is trivial (container_of style
>> cast).  So the QOBJECT() macro becomes comparable to a C++
>> reinterpret_cast<>() that converts any descendent of QObjectCommon into
>> QObject, even if the original type was not QObject; and we never offer a
>> public API to convert anything into or out of QObjectCommon (it only exists
>> as a dummy type to make our other casts easier).
> What is the QOJECT() macro you proposed with that?

#define QOBJECT(x) \
   container_of(&(x)->base, QObject, base)

where the double dereference-and-container_of provides some type safety
(container_of fails if &(x)->base is not a QObjectCommon*).

Paolo

Reply via email to