Somewhat off topic (more general discussion of that paper, not really
related to anything in the OP), but I'm concerned by how little
knowledge of Qt's MOC is displayed in P0707. In particular, it gives
these examples of properties:
Q_PROPERTY(int value READ get_value WRITE set_value)
int get_value() const { return value; }
void set_value(int v) { value = v; }
...but this is NOT AT ALL what real properties in Qt look like.
Here is a real example:
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
Note that NEITHER the getter nor setter have names that are trivially
derived (e.g. string concatenation). This information needs to be
communicated somehow. It's also not obvious how the `property` results
in injection of methods into the parent class.
The *idea* of P0707 is interesting, but until someone can *demonstrate*
— meaning, an actual functioning demo with real code, not some
ignorance-revealing hand-waving — that it can replace MOC, I'm not
convinced that it is a viable, complete proposal. At the very least, I
feel like the MOC example should be removed, since it is really
something of a lie.
Another problem is locality of code. Due to compatibility constraints,
it is *critical* that the implementation of many functions is
non-inline. Maybe modules will alleviate or solve this, but until that
happens, the only way P0707 stands a chance of replacing MOC is to know,
somehow, if it should generate code because it is in the class's
implementation TU, or if it should generate only prototypes. Possibly I
missed it(? ...it's a long paper, after all), but I don't recall seeing
anything to this effect in the proposal.
I'd like to see, for example, how the proposed tools would implement this:
qobject QLineEdit : public QWidget
{
qproperty<bool> modified{
.read = isModified,
.write = setModified
};
qproperty<QString> text{
.read = text,
.write = setText,
.notify = textChanged
};
// ...
public:
bool isModified() const; // note: NOT inline!
void setModified(bool); // note: NOT inline!
// ...
void setText(QString);
void setText(/*... some overload ...*/);
public: // signals
qsignal textModified();
};
Besides the issue of where certain special function definitions reside,
as discussed above, some issues that this would need to address that
P0707 does not obviously cover include:
- Implicit inheritance when the class is already a descendant of
QObject. (Practically speaking, the above example is inaccurate; there
would almost certainly be a $qwidget meta-class in addition to $qobject,
but I've written it that way to demonstrate this issue.) Presumably
reflection will be able to sort this out, but it seems important enough
to not just gloss over.
- Terse syntax for linking a meta-object (note: the $qproperty must
result in code generation, but otherwise must eventually disappear from
the class without creating members) to other members of the enclosing
class. I've used named initializers as the most terse but still
syntactically valid construct that came to mind. Moving the definitions
of the get/set functions into the $qproperty is not appropriate; in most
cases, they cannot be inline due to PIMPL, and writing thunks is
pointless repetition. The approach shown is MUCH more palatable than
what is presented in P0707. (Ideally, this should also be able to accept
not only an identifier which is a member function of the parent class,
but one with a specific signature, without choking and dying in the face
of overloads. However, use of a string literal might be palatable;
presumably code generation can turn it back into an identifier.)
--
Matthew