[Interest] QPlugin and RTTI

Till Oliver Knoll till.oliver.knoll at gmail.com
Tue Jun 24 09:19:36 CEST 2014


Am 23.06.2014 um 19:13 schrieb Till Oliver Knoll <till.oliver.knoll at gmail.com>:

> ...
> And I /still/ think that was exactly one of the (many) selling points of using the Qt Meta Object over the RTTI, because the later is /not/ guaranteed to work "across DLLs" when it comes to dynamic casting... it even sais (said) so in the Qt docs, IIRC.

Here's a link that I quickly found which seems to confirm that at least at /some/ point in the past /some/ compilers did not support "dynamic casting across library boundaries using RTTI":

http://stackoverflow.com/questions/21314557/why-does-qt-reimplement-rtti-in-qobject-cast-event-type-etc

"Historically, with some compilersdynamic_cast failed across shared library boundaries."

(And no, the Stack Overflow answer wasn't given by me ;))

I think what Thiago meant by the "single library constraint" was simply: "make sure that the generated meta info code is only compiled and linked into one library (preferably the one which also implements the class), and not into several (-> multiple symbols!)" - E.g. by accidentally add the class header to several *.pro HEADER entries, such that it gets mocced and compiled several times (but why would you do that?).

Given the fact that the moccing is all automated with qmake (and assuming that you don't rename or #include the generated files in some "funny way" which might lead to pitfalls) I don't remember having ever problems with that. 

The only problem I do remember however is that the generated code was not "DLL exported": in order to keep the "export table" to a minimum I usually only export the (public/protected) methods (members) of a class that I really want to be callable from outside the library (you know, that "__dllexport / __dllimport" stuff - which also provides somewhat another "module" level of visibility, besides public/protected/private).

For QObject derived classes however using the Qt Meta Object system (and having the Q_OBJECT macro properly defined in their class declaration) one needs to export the /entire/ class. Otherwise the generated code (giving access to the meta system) would not be "visible" from outside the library (-> linker error).

That's the only "pitfall" that I remember. But maybe I am just overlooking the most obvious pitfall here?

Cheers,
  Oliver
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140624/c7af1768/attachment.html>


More information about the Interest mailing list