[Qt-interest] qobject_cast<>() and objects from dynamically loaded libraries

Jaco Naude naude.jaco at gmail.com
Wed Jan 21 15:29:39 CET 2009


I've had the same problem in the past. I found an answer to why it didn't
work in the following thread:

http://www.qtcentre.org/forum/f-qt-programming-2/t-casting-result-of-qwidgetstack-currentwidget-5037.html

Cheers,
Jaco

On Wed, Jan 21, 2009 at 2:51 PM, Dmitry Nezhevenko <dion at inhex.net> wrote:

> Hi guys.
>
> I'm experiencing strange behaviour of QObject cast. Basically I've code
> like:
>
> class Base: public QWidget
> {
>        Q_OBJECT
> };
>
> class SomeImpl: public Base
> {
>        Q_OBJECT
> };
>
> On Win32 I have some function DLL-exported that returns pointer to QWidget:
>
> QWidget *getWidget();
>
> After loading library (LoadLibrary && GetProcAddress) and calling to
> getWidget() I'm trying to cast returned pointer to Base:
>
>        Base *b = qobject_cast<Base *>(w);
>
> And b = 0 here. I'm sure that w is correct pointer. For example I can do:
>
>        QString className = w->metaObject()->className();
>
> And className became "SomeImpl". Also debugger shows that w is instance of
> SomeImpl
> and contains Base.
>
> Also dynamic_cast works as expected. Any ideas why qobject_cast returns
> zero?
>
> PS. Qt 4.4.3, MSVC2005
>
> --
> WBR, Dmitry
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFJdxo30T/aIlRaJQYRAhN6AKCDLnHE4fqNGyPjR++KgYZPqt5VAwCbBgio
> Sa+3cIFL+CJe4wKG8rxEtOM=
> =uSrL
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090121/a39c503f/attachment.html 


More information about the Qt-interest-old mailing list