Important: Please read the Qt Code of Conduct -

Debug assertion fail when nesting QSplitters in QWidget

  • !!

    Debug Assertion Failed!
    File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cpp
    Line: 52
    Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

    This happens when you nest QSplitters in the wrong way. Anyone know why? Here's a simple example that recreates the problem

    @#include <QPlainTextEdit>
    #include <QSplitter>
    class brokenwidget : public QWidget{
    brokenwidget(QWidget *parent = NULL);
    QPlainTextEdit jnk1, jnk2, jnk3;
    QSplitter middle, bottom;

    @#include "brokenwidget.hpp"
    brokenwidget::brokenwidget(QWidget *parent){

    @#include "brokenwidget.hpp"
    int main(int argv, char **args){
    QApplication app(argv, args);
    brokenwidget wid = brokenwidget();;
    return app.exec();

  • Moderators

    Hi, and welcome to the Qt Dev Net!

    The crash happened because your widgets got deleted twice.

    To avoid this problem, allocate your member variables on the heap using new. See "Object Trees & Ownership": for details.

  • Qt Champions 2017

    When is this happening ? Is it happening when you close the window ? Here when close the window, it is trying to freeup all the child widgets of splitter. Since they are not allocated on the heap, it is getting into this problem. QSplitter has no way of knowing whether it is allocated on heap or member variable. It may be hitting this issue.

    Also what is wrong of nesting here ? I did not see any issue with that.

    Also you can do the following

    @QPlainTextEdit *edit = new QPlainTextEdit;
    QPlainTextEdit *edit1 = new QPlainTextEdit;
    QPlainTextEdit *edit2 = new QPlainTextEdit;

    QSplitter *top = new QSplitter(this);
    QSplitter *bottom = new QSplitter(this);


  • Oh. Thanks for the tip

    I try to avoid heap allocation. And for some reason it seems like every example program is full of memory leaks because nobody saves their pointers and deletes them later.

    Does Qt have some sort of garbage collection for QWidgets?
    Why are they being deleted twice? Shouldn't each individual object's destructor handle itself?
    I don't understand why this should happen at all. Which ones specifically get deleted twice, when, and why?

  • Lifetime Qt Champion


    It's all explained in QObject's "documentation":

  • Moderators

    [quote]Does Qt have some sort of garbage collection for QWidgets?[/quote]Yes. Read the links that SGaist and I gave you.

    They get deleted once by the garbage collector. Then, they get deleted again when they get removed from the "stack". That's why you should use the heap instead.

Log in to reply