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. Crash on exit, stack smashing detected
Forum Updated to NodeBB v4.3 + New Features

Crash on exit, stack smashing detected

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.0k Views
  • 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.
  • pauleddP Offline
    pauleddP Offline
    pauledd
    wrote on last edited by
    #1

    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?

    KroMignonK 1 Reply Last reply
    0
    • pauleddP pauledd

      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?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @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?

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      pauleddP 1 Reply Last reply
      0
      • KroMignonK KroMignon

        @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?

        pauleddP Offline
        pauleddP Offline
        pauledd
        wrote on last edited by
        #3

        @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
        
        1 Reply Last reply
        0
        • pauleddP Offline
          pauleddP Offline
          pauledd
          wrote on last edited by pauledd
          #4

          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.

          1 Reply Last reply
          1

          • Login

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