[Development] templates as QObjects

Peter Kümmel syntheticpp at gmx.net
Wed Jun 27 11:33:52 CEST 2012


On 26.06.2012 23:17, Olivier Goffart wrote:
>
> I'm not sure the class name is that important.
> I mean, if  Foo<int>().metaObject()->className() is just "Foo" it is still ok.
> Because it is hard to support, and hardly usefull.

OK, I thought className() is used by qobject_cast, but it isn't,
so it's maybe really not that important.

But I could imagine when you do alot gui stuff dynamically the
class name would be usefully. A simple grep and wc in qtbase/src
gives 158 hits, so it is used.

>
> Also remember that template parametter can be more complex than just a type.
> It probably should support stuff as complicated as this
>
> template<template<typename ... U>  class T,
>            typename T<>::size_type = sizeof(T<>)>  class Bar;
> (I think i made that quite complicated already)

Yes, currently removing 'class' and 'typename' within <...> must
give valid signature, anything else is not supported. But this is
an isolated piece of code, and could be replaced by a more
sophisticated code later.

>
> The fact that you have that macro Q_QOBJECT_TEMPLATE_USED limit you to only
> one parametter (because you cannot have coma in macro)
> (But we could say it is ok to only support multple parametter with compiler
> that support variadic macros)

Or we introduce
Q_QOBJECT_TEMPLATE_USED_1(x)
Q_QOBJECT_TEMPLATE_USED_2(x,y) ...

>
>
> But to answer your question, the extraData is not being used currently and is
> reserved for future use, so yes, it can be used.
>

What is missing atm, are some tests for linking. I assume there will
be linker errors because of the statics when the header is included
in multiple files. And for Dlls it would be even more complicated.

Peter



More information about the Development mailing list