[Qt-interest] Problems with QT custom types in dll's
Santosh Puranik
santosh.puranik at nokia.com
Sun May 16 19:16:15 CEST 2010
Hello,
We ran into the following problem with custom types added to QT's meta
type system. The attached example illustrates this problem.
-- We have a type (struct) MyCustom which is a part of a shared library
testlib.
-- The type is declared to the QT type system using
Q_DECLARE_METATYPE(MyCustom).
-- The testlib is dynamically loaded into the main program (TestQT)
using dlopen()
-- The function Testlib::doThings() constructs a QVariant from our
custom type.
-- The problem happens when we dlclose() the testlib, dlopen() it again,
and then call Testlib::doThings.
As there is no guarantee that testlib will be loaded at the same base
address (the test program does this by dlopen-ing another lib,
testlibnew before loading testlib again), QT holds a stale
QCustomTypeInfo in it's global custom types vector.
This results in bad function calls, (and hence weird crashes) to what QT
still thinks are the constructor and destructor helper functions for the
custom type.
Is there a way around this? Unregistering the custom type before the lib
gets unloaded (in destroyLib()) works. However, there could still be a
similar issue with the DBus custom types (there is no function that can
be used to unregister these).
This is not documented in the QMetaType documentation. It should be done
so that such errors can be avoided. Also, a qUnregisterDBusType() or
similar must be added, so that the DBus types marshall/unmarshall helper
functions can also be cleared before unloading the library.
Best Regards,
Santosh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: variant_crash.tar.bz2
Type: application/x-bzip
Size: 1765 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100516/9b79a1e6/attachment.bin
More information about the Qt-interest-old
mailing list