Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Debug assertion fail when nesting QSplitters in QWidget
Forum Updated to NodeBB v4.3 + New Features

Debug assertion fail when nesting QSplitters in QWidget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    a15peterj231
    wrote on last edited by
    #1

    !http://puu.sh/aW6uJ.png()!

    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

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

    brokenwidget.cpp
    @#include "brokenwidget.hpp"
    brokenwidget::brokenwidget(QWidget *parent){
    middle.addWidget(&jnk1);
    middle.addWidget(&jnk2);
    bottom.addWidget(&middle);
    bottom.addWidget(&jnk3);
    }@

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

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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":http://qt-project.org/doc/qt-5/objecttrees.html for details.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        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);
        top->addWidget(edit);
        top->addWidget(edit1);
        
        QSplitter *bottom = new QSplitter(this);
        top->setOrientation(Qt::Vertical);
        top->addWidget(bottom);
        top->addWidget(edit2);
        

        @

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • A Offline
          A Offline
          a15peterj231
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            It's all explained in QObject's "documentation":http://qt-project.org/doc/qt-5/qobject.html#details

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              [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.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved