[Development] QProperty and library coding guide

Jean-Michaƫl Celerier jeanmichael.celerier at gmail.com
Fri Jul 17 14:17:16 CEST 2020


> We are not casting these structs to or from anything though, do we?

...

>    const auto *thisPtr = reinterpret_cast<const
QQmlComponent*>(reinterpret_cast<const char *>(this) -
propertyMemberOffset);

sounds pretty much like the structs are indeed being casted to / from
anything <_<


On Fri, Jul 17, 2020 at 2:13 PM Ulf Hermann <ulf.hermann at qt.io> wrote:

> >> The struct has no data itself, so ideally would be of size zero.
> >
> > I'm missing some piece of the puzzle: if you take action->text, and text
> > is a zero-size struct, how does the operator() applied to it figure out
> > which action needs to read the text property from? E.g. like so:
> >
> >> QAction *action = ~~~;
> >> auto prop = action->text;
>
> This already gives you the string. You cannot retrieve the property
> itself. You can alternatively do action->text() or action->text.value().
> They all do the same thing.
>
> The member to access in the private object is hardcoded in the generated
> implementation of value(). The public object to pick the private object
> from is retrieved by offset from the address of the property. moc
> generates code like this:
>
> qreal QQmlComponent::_qt_property_api_progress::value() const
> {
>      const size_t propertyMemberOffset =
> reinterpret_cast<size_t>(&(static_cast<QQmlComponent
> *>(nullptr)->progress));
>      const auto *thisPtr = reinterpret_cast<const QQmlComponent
> *>(reinterpret_cast<const char *>(this) - propertyMemberOffset);
>      return thisPtr->QQmlComponent::d_func()->progress.value();
> }
>
> I see where you're coming from. If the address doesn't exist, this
> shouldn't be possible. However, no_unique_address does not mean that the
> object has no address. It just means that it can share the same address
> with other objects.
>
> best,
> Ulf
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200717/a8649a43/attachment.html>


More information about the Development mailing list