Hi,
I have a program which is based on QT and runs the QApplication. Now, I load a widget from a DLL which uses two QwtPlotCurve objects.
Hence, internally, I use a QwtLegendData object somewhere which belongs to the loaded DLL. Everything is fine so far.
Now, I unload the DLL and reload it afterwards. When trying to attach the curves in the newly loaded DLL, the application crashes.
I have isolated the problem up to a certain point but would like to discuss it here:
By browsing the call stack, I find that the problem is deep inside QT in the handling of the creation of a QVariant:
It seems that Qwt added a specific QVariant type together with a callback for object creation, presumably
in the Qwt initialization phase. In my case - the associated object type is a QwtLegendData object.
For this object type, the Qvariant and associated creation function are, e.g., employed in the function
call QwtPlotItem::legendData() by calling qVariantSetValue(...).
The problem seems to arise from the associated callback for object creation as stored with the
QVariant: It was added initially when the DLL was loaded for the first time but now -as the DLL was unloaded and reloaded -
it is no longer valid: As soon as I unload the DLL the main application still operates and does not de-reference the QVariant callback for creation,
and when reloading the DLL, it seems that the callback function pointer is sometimes updated properly, sometimes not.
If not, Qt points to the old symbol which is no longer valid since the DLL was unloaded and when calling the creator function for the first time
given the newly loaded DLL, the invalid old symbol stored for the QVariant type leads to the crash.
I have the feeling that this is due to a race condition: the QVariant initialization code happens in the "dll load" thread
whereas the allocation functionality happens in the "QT thread". A sleep of 1 sec right before the call to the QWT functions seems
to solve the issue..
Could anyone confirm this behavior? Is there a limitation for using Qwt widgets allocated in DLLs which may be unloaded during runtime?
Note that this did happen on a system Visual Studio 2012, Qwt 6.1.0 and Qt5 whereas on a system with Visual Studio 2010, Qwt 6.0.2 and Qt5,
the problem does not occur.
Thank you in advance and best regards
Hauke
Bookmarks