Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Crash on exit, stack smashing detected



  • Its been a long time since I wrote my last Qt/C++ code but now I encounter a possibly very very stupid error.

    I have this simple window that crashes when I click the close button.

    *** stack smashing detected ***: terminated
    10:17:37: The program has unexpectedly finished.
    

    main.cpp

    #include <QApplication>
    #include "mainwindow.h"
    int main(int argc, char *argv[])
    {
        QApplication app(argc,argv);
        Window window;
        window.show();
        return app.exec();
    }
    

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QWidget>
    #include <QHBoxLayout>
    #include <QLabel>
    
    class Window : public QWidget
    {
        Q_OBJECT
    public:
        explicit Window(QWidget *parent = 0);
    private:
       QHBoxLayout *hboxlayout;
       QLabel *lb_cmref;
    };
    
    #endif // MAINWINDOW_H
    

    mainwindow.c

    #include "mainwindow.h"
    
    Window::Window(QWidget *parent)
        :QWidget(parent)
    {
        hboxlayout = new QHBoxLayout();
        //QHBoxLayout *hboxlayout = new QHBoxLayout();
        lb_cmref = new QLabel("CMREFCTL");
        hboxlayout->addWidget(lb_cmref);
        this->setLayout(hboxlayout);
    }
    

    The problem seems the QHboxlayout and its creation/deletion...
    if I create it directly in the mainwindow.c file like this:

    QHBoxLayout *hboxlayout = new QHBoxLayout();
    

    then the application does exit without error.
    Whats the problem here?



  • @pauledd said in Crash on exit, stack smashing detected:

    The problem seems the QHboxlayout and its creation/deletion...
    if I create it directly in the mainwindow.c file like this:
    QHBoxLayout *hboxlayout = new QHBoxLayout();

    then the application does exit without error.
    Whats the problem here?

    I can't believe the problem is here, were else do you use hboxlayout?



  • @KroMignon said in Crash on exit, stack smashing detected:

    I can't believe the problem is here, were else do you use hboxlayout?

    There is no more code than in my first post. Except the *.pro file maybe:

    CONFIG += core gui debug
    
    SOURCES += \
        main.cpp \
        mainwindow.cpp
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    HEADERS += \
        mainwindow.h
    


  • Okay, this was really weird. I did a "BUILD->Clean Project "" for all configuration" and rebuild it and the problem is gone...

    Maybe I messed with some garbage remnant... never mind!
    Marked as Solved.


Log in to reply