[Development] [Feature] Q_INFO: Annotations for classes, methods, properties and enums

Thiago Macieira thiago.macieira at intel.com
Wed Sep 11 21:49:35 CEST 2013


On quarta-feira, 11 de setembro de 2013 12:03:52, Matt Broadstone wrote:
> On Wed, Sep 11, 2013 at 2:33 AM, Olivier Goffart <olivier at woboq.com> wrote:
> >  Q_INFO("foo", "bar")
> >  Q_PROPERTY(int bar READ bar)
> >  Q_INFO("foo", "baz")
> >  Q_PROPERTY(int baz READ baz)
> >
> >
> >  Q_PROPERTY(int bar READ bar INFO "foo" = "bar")
> >  Q_PROPERTY(int baz READ baz INFO "foo" = "baz")
> 
> I think this is too verbose. If we're already headed towards java-style
> annotations why not just have an annotate that can align with a Q_PROPERTY:
> 
> Q_PROPERTY(int bar READ bar WRITE setBar)
> (this gives us a good, clear definition of the property)
> 
> Q_ANNOTATE(bar, foo = "baz", abc  = "cde")
> (this annotates the aforementioned property, and is a specialization of the
> "normal" Q_ANNOTATE, and can appear anywhere in the class definition)

Sorry, I'm setting my foot down now: do not use Q_INFO / Q_ANNOTATE / 
whatchamacallit for properties. Place the annotation inside the Q_PROPERTY.

Compare the two proposals above:

Olivier used Q_INFO before Q_PROPERTY. Matt used Q_PROPERTY before Q_INFO.

I call that mightily confusing. So Q_INFO applying to a Q_PROPERTY is out of 
the question.

For the same reason, Q_INFO applying to the whole class while *inside* the 
class body is also out of the question. It could be placed outside of the 
class:

class Q_INFO("Foo" = "bar") Q_DECL_EXPORT Q_DECL_ALIGN(16) Foo : public Bar
{ };

Whoever wants to implement that, please study the C++11 attributes and GCC 
attributes[1]. Note the differences below:

Q_INFO("x", "y")
class Q_INFO("t", "w") Foo : public QObject 
{
	Q_OBJECT
public slots:
	Q_INFO("foo" = "bar") 
	void Q_INFO("a" = "b") slot1(),
		Q_INFO("c" = "d") slot2();
} Q_INFO("blah", "blubb") 
	obj Q_INFO("trailing", "trailing");

I'm not sure which of those are valid syntax and which ones aren't; which ones 
apply to which, etc. Also, apparently there's a disagreement between the GCC 
syntax and the C++11 syntax.

[1] http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Attribute-Syntax.html

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130911/85caae61/attachment.sig>


More information about the Development mailing list