[Interest] Tempalted QObjects

Thiago Macieira thiago.macieira at intel.com
Wed Feb 24 20:50:15 CET 2016


On quarta-feira, 24 de fevereiro de 2016 20:13:44 PST Jean-Michaƫl Celerier 
wrote:
> I saw some other approaches to produce static reflection information by
> libclang usage,
> would inspired approaches be acceptable ? e.g.
> https://github.com/AustinBrunkhorst/CPP-Reflection/
> 
> Also, why is "#include'ing it from your class's header file," considered
> bad ?

Because it means that you need to install the Moc output as a header file for 
ALL of your users to include. The output isn't meant for that, as it has an 
#if check that you're compiling against the QtCore headers which came along 
with the moc that created that output. It also declares functions and 
variables that aren't properly namespaced for headers, and it declares static 
variables that would end up in every since translation unit that #included the 
output.

And that's just what we can fix, with some work.

> In "standard" Qt software, it is sometimes useful to #include
> "foo_moc.cpp"  (or foo.moc, I don't remember)
> in the implementation file, for instance if multiple classes are defined in
> the same header IIRC.

Right, but you're including it from the .cpp and you never distribute that 
moc_foo.cpp file.

We're talking about including it from a header and distributing that with your 
software so your users include it too (indirectly).

> But when doing template-heavy software the .hpp have more or less the same
> role
> for the developer that "traditional" implementation files so it should not
> come as shocking to require
> inclusion of files in the .hpp. But it's only my personal opinion.

We find that poor coding practice. All-inline template code leads to template 
bloat because the no compilers is currently able to merge implementations that 
produce the same code, if they come from different functions.

Qt takes care to fall back to a common implementation, often non-inline, for 
its template classes whenever it can.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list