[Development] QProperty and library coding guide

Ulf Hermann ulf.hermann at qt.io
Fri Jul 17 13:37:04 CEST 2020


> if it's all "fake" anyway, what exactly is the point of having that 
> struct in the first place? is it just to have an "anchor" in the 
> pre-processed code / AST?

The idea is that you can use the same name as getter and for 
assignment/binding/subscribe etc:

something = item->width();
item->width.onValueChanged([]() { qDebug() << "changed"; });
item->width = 44;
item->width.setBinding([]() { return otherItem->height(); });
[...]

We could instead establish a convention of using different names for all 
of these, but (at least to me) it feels ugly. The result would look like 
this:

auto something = item->width();
item->widthOnValueChanged([]() { qDebug() << "changed"; });
item->widthAssign = 44; // drop in favor of classic setWidth()?
item->widthSetBinding([]() { return otherItem->height(); });
bool hasBinding = item->widthHasBinding();
auto binding = item->widthBinding();
item->takeWidthBinding();
[...]

See the definition of Q_PRIVATE_QPROPERTY for the different methods we 
generate into the structs.

best,
Ulf


More information about the Development mailing list