[Development] QProperty and library coding guide
Thiago Macieira
thiago.macieira at intel.com
Fri Jul 17 17:10:30 CEST 2020
On Friday, 17 July 2020 04:54:08 PDT Giuseppe D'Angelo via Development wrote:
> Il 16/07/20 17:40, Volker Hilsheimer ha scritto:
> > 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:
The same way this works:
auto l1 = [] { return 1; };
auto l2 = [] { return 2; };
Both l1 and l2 are "zero" sized closure types with an operator(). When you
call them, you get different results, because the C++ compiler will place a
call to different functions.
Note: that's different from:
auto f1 = +[] { return 1; };
auto f2 = +[] { return 2; };
The unary + forces the stateless lambda to cast to void(void), so f1 and f2
are the same type (a function pointer) and have different values.
> > QAction *action = ~~~;
> > auto prop = action->text;
> > QString text = prop();
Note on the above: the type should not have a cast operator. Otherwise:
auto prop = action->text;
QString value = action->text;
would be different things. Not to mention QString builder failures. People
should always write action->text().
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel System Software Products
More information about the Development
mailing list