Am 14.05.2012 um 18:34 schrieb Thiago Macieira <[email protected]>:

> On segunda-feira, 14 de maio de 2012 17.49.03, Till Oliver Knoll wrote:
>> I prefer:
>> 
>> class Foo : public QObject {
>>  Q_OBJECT
>> public:
>>  FOO_API Foo(); // c'tor
>>  FOO_API virtual ~Foo();
> 
> ...
> 
> If you try to derive from this class or use qobject_cast, you'll get linker 
> errors.

Yes, absolutely correct! My approach only works for non-Qt based classes (where 
the selective export gives you some kind of an additional "package visibility" 
level, besides public/protected/private), where no generated code needs to be 
exported.

So the above example I gave is wrong!


Talking about qobject_cast: it is also worth mentioning in this context that it 
works across dynamic library boundaries, because it relies on (generated) code, 
in contrast to its counterpart dynamic_cast, which relies on RTTI information 
generated by the compiler, but which does not (always) work across dynamic 
libraries (probably depending on the actual compiler).

Off course the former only works if *every* class in the QObject inheritance 
chain declares the Q_OBJECT macro, to repeat that as well.

Cheers,
  Oliver
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to