[Development] QProperty and library coding guide
Ulf Hermann
ulf.hermann at qt.io
Fri Jul 17 14:09:22 CEST 2020
>> 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
More information about the Development
mailing list