QCustomPlot Discussion and Comments

Subclassing QCP in shared libraryReturn to overview


I'm faced with an issue i can't solve and don't even know if it's related to Qt, QCP or my deficiency...

I use QCP as a shared library, compiled with the provided pro file.
I want to create a shared library with a custom object subclassing qcp and have many crashes using it in an application (starting or closing the application). If i don't use shared libraries (what i'v done for 2 years with this application), everything is fine.

So i just created a simple test below to reproduce the behavior and it crashes when i close the app, gdb can't tell me where the sigsev appears and valgrind just tells me that there is a jump to an invalid address.

So here is my subclass implementation :

Board::Board(QWidget *parent) : QCustomPlot(parent)
    mLayout = new QCPLayoutGrid();

    delete mLayout;
    mLayout = nullptr;

And my app main :

int main(int argc, char *argv[])
    QApplication a(argc, argv);

    Board t;

    return a.exec();

Can someone reproduce the issue ? I can provide the pro files if needed...

No issue when i remove
DEFINES += QCUSTOMPLOT_USE_OPENGL from the pro file...

What stands out to me is that you're trying to manage the memory of QCPLayoutGrid yourself. Usually a layout element is passed to QCustomPlot at some point so it becomes usable at all (by a call to addElement), at which point it becomes owned and memory-managed by QCustomPlot. So your additional delete in ~Board may be the problem, since you delete memory that is freed a second time in the base class destructor.
Possibly the OpenGL thing just hides that error as memory layout changes (same with static/dynamic linking).

Thanks for your reply.
From my understanding, the element is memory-managed by QCP if it is owned by the default QCP layout mPlotLayout, which will take care of all its child.

Actually, in my project, i use a subclass of QCPLayoutGrid and was facing a segfault when instantiating my layout and using shared library (same error, jump to invalid address when trying to initialize a class member). So to discover what was wrong in my code, i carefully removed all the attributes from my QCP subclass and QCPLayoutGrid subclass. It led me to this piece of code where i don't even use a subclass of QCPLayoutGrid and still have a sigsev...