[Interest] qobject_cast, static libraries and plugins
jkt at flaska.net
Fri Aug 9 17:47:12 CEST 2013
Hi, it looks that I cannot use qobject_cast in the following scenario:
0) Everything is built with -fPIC
1) class Foo: public QObject is defined in a *static* library libCommon
2) A plugin is statically linked with libCommon and has a function
returning subclasses of class Foo; these subclasses are compiled into the
plugin (main app doesn't include their headers)
3) Main application is statically linked with libCommon, loads the plugin
from step 2) at runtime (i.e. from a shared library), calls the plugin's
function and performs a qobject_cast<Foo*> to see if the returned instance
is of the correct type
The problem is that qobject_cast returns zero while dynamic_cast works.
There's something  suggesting that this is expected and that one has to
move Foo into a shared library so that there's just one instance of a
QMetaObject. Is that correct, or is the problem somewhere else?
This is in a code from my GSoC student which contains plenty of new
features, so I don't have a standalone use case. What I'd like to know is
whether this is *supposed* to work, or something that I shouldn't be doing
in the first place.
With kind regards,
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/
More information about the Interest