Architecture of my project looks as follows:
Main project, that is compiled as stand-alone application:
TEMPLATE = app
Sub projects, that are compiled as libraries:
TEMPLATE = lib
Plugins, that are compiled as Qt Plugins:
CONFIG += plugin
TEMPLATE = lib
Common directory, that contains libs used by more than one element, f.e. all sub projects and one plugin.
TEMPLATE = lib
---
Main project accesses Sub projects as a libraries:
INCLUDEPATH += \
$$(SUB)/my_sub_pro1/lib \
DEPENDPATH += \
$$(SUB)/my_sub_pro1/lib \
LIBS += \
-L$$(BUILD_SUB)/lib -lmy_sub_pro1\
Sub projects access plugins by using standard QPluginLoader. I'm checking all files in my plugin build directory and cast them:
QObject *plugin
= loader.
instance();
myPluginInterface* plugin = qobject_cast< myPluginInterface* > (plugin);
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
QObject *plugin = loader.instance();
myPluginInterface* plugin = qobject_cast< myPluginInterface* > (plugin);
To copy to clipboard, switch view to plain text mode
Any Main, Sub or plugin project that would like to use commons, is simply including them:
SOURCES += \
$$(COMMON)/common/calc.cpp
HEADERS += \
$$(COMMON)/common/calc.h
---
I've got problem with my application crashing without reason on closing: It crashes in malloc.c: malloc_consolidate (Full stack below). This makes it incredibly hard to debug. I used Valgrind till the moment it doesn't show any memory leaks, but the problem persists. My friend once told me, that he had some problems while using static variables in plugins. I think he was right, because when I got rid of them me application is now crashing less often. I also had a small problem after adding a constexpr, but after some time the problem disappeared and I couldn't reproduce it.
I cannot possibly paste all the code that might be causing problems. However I would like to sincerely ask for any idea that might cause problems on destruction in architecture that I'm using. I will be really thankful for any idea on what to check or what could be potential problems while creating program that is using a dynamic library that is using plugins. I couldn't find any similar topic on problems with Qt Plugins.
It is worth to mention that crash only occurs on closing, and all destructors are called properly. What is more, when I created a stand-alone program that simply uses one Subprogram with plugins it works perfectly. Additionally if I use MainProgram to call any Subprogram without plugins it also works effortlessly. I'm using Qt 5.3.2.
Stack view on crash:
0 malloc_consolidate malloc.c 5206
1 _int_free malloc.c 5079
2 QArrayData::deallocate 130
3 QTypedArrayData<int>::deallocate 234
4 QVector<int>::freeData 473
6 QRegExpEngine::~QRegExpEngine 1356
7 QCache<QRegExpEngineKey, QRegExpEngine>::clear 126
8 QCache<QRegExpEngineKey, QRegExpEngine>
::~
QCache 95 9 (anonymous namespace)::Q_QGS_globalEngineCache::Holder::~Holder 3825
10 __cxa_finalize cxa_finalize.c 56
11 __do_global_dtors_aux /opt/Qt-5.3.2/lib/libQt5Core.so.5
12 ??
13 _dl_fini dl-fini.c 254
0 malloc_consolidate malloc.c 5206
1 _int_free malloc.c 5079
2 QArrayData::deallocate 130
3 QTypedArrayData<int>::deallocate 234
4 QVector<int>::freeData 473
5 QVector<int>::~QVector 76
6 QRegExpEngine::~QRegExpEngine 1356
7 QCache<QRegExpEngineKey, QRegExpEngine>::clear 126
8 QCache<QRegExpEngineKey, QRegExpEngine>::~QCache 95
9 (anonymous namespace)::Q_QGS_globalEngineCache::Holder::~Holder 3825
10 __cxa_finalize cxa_finalize.c 56
11 __do_global_dtors_aux /opt/Qt-5.3.2/lib/libQt5Core.so.5
12 ??
13 _dl_fini dl-fini.c 254
To copy to clipboard, switch view to plain text mode
Bookmarks