Qt World Summit: Submit your Presentation

SIGSEGV on QTabWidget::close

  • Hi there,

    I have a problem with proper closing my application without a SIGSEGV.

    My window is made of a QTabWidget derived widget. The tabwidget
    has four tabs and each has an ordinary qwidget in it.

    class TabWidget : public QTabWidget
        explicit TabWidget(QTabWidget *parent = Q_NULLPTR);

    In one of the tabs qwidget I have a pushbutton that is connected to the tabwidgets
    close() function.


    If I press the button (or click on the close window cross) the application quits with SIGSEGV:

    The program has unexpectedly finished.
    The process was ended forcefully.
    /home/paul/store/c++/qt/build-qt-wetter-0.7-Desktop-Debug/qt-wetter-0 crashed.

    If I debug the app it shows me the arrow where the error might be but the arrow is pointing at the Tabwidget class declaration itself, how could I debug further to find the problem?


  • Lifetime Qt Champion


    Do you have any of your widgets on the stack and giving it a parent at the same time ?

  • An other possibility is you having set the Qt::WA_DeleteOnClose attribute

  • @VRonin I indeed set that flag attribute, just to see if that changes something but removing it does not solve it.

    @SGaist no, the widgets I use for the tabs do not have a parent,

    tab1 = new QWidget;
    tab2 = new QWidget;
    tab3 = new QWidget;
    tab4 = new QWidget;
    this->addTab(tab3, "Graph");
    this->addTab(tab4, "System");

    I will try to comment out parts of my code to condense the problem

  • Okay I am getting closer, I found a line in the TabWidget constructor where I add a QHBoxLayout to a VBoxLayout (addLayout)... that causes the trouble. Trying to fix that :)

  • That faulty QHBoxLayout has the problem that I added a QSpacerItem (addSpacerItem) to it two times... So I guess that is not the right way to use QSpacerItem? Can it only be added once to a QHBoxLayout?

    Normally, you don't need to use this class directly. Qt's built-in layout managers provide the following functions for manipulating empty space in layouts


  • Solved my removing all addSpacerItems.

Log in to reply