[Interest] Link Errors when Creating a Windows DLL containing Qt Widgets

Till Oliver Knoll till.oliver.knoll at gmail.com
Mon May 14 22:40:32 CEST 2012





Am 14.05.2012 um 18:34 schrieb Thiago Macieira <thiago.macieira at intel.com>:

> 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


More information about the Interest mailing list