Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Segmentation fault(core dumped) occured after add an private member in widget class.
Forum Updated to NodeBB v4.3 + New Features

Segmentation fault(core dumped) occured after add an private member in widget class.

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 3 Posters 856 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.
  • HupeH Offline
    HupeH Offline
    Hupe
    wrote on last edited by
    #1

    I am building a tool with QT 5,12 to run in the arm64 board. It run well when there was only one private member. When I add more private members, it can compile successfully, but run to the segmentation fault.

    QT_BEGIN_NAMESPACE
    namespace Ui { class Widget; }
    QT_END_NAMESPACE
    
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
        Widget(QWidget *parent = nullptr);
        ~Widget();
        QLCDNumber    *rebootTimeLcdNum;
        QTimer *mtimer;
    
    private:
        Ui::Widget *ui;
        QPushButton *startButton;
        //QLCDNumber    *rebootTimeLcdNum;
        //QTimer *mtimer;
        //int a;
    
    private slots:
        void on_startButton_clicked();
        void onTimerTimeout();
    };
    
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::Widget)
    {
        ui->setupUi(this);
        connect(startButton, SIGNAL(clicked()), this, SLOT(on_startButton_clicked()));
     } 
    

    I use gdb to debug and find that the fault occurred when connecting the slot function on_startButton_clicked() . And the fault won't occur if I put the member to public.

    Does anyone experencd the same problem?

    jsulmJ 1 Reply Last reply
    0
    • HupeH Hupe

      I am building a tool with QT 5,12 to run in the arm64 board. It run well when there was only one private member. When I add more private members, it can compile successfully, but run to the segmentation fault.

      QT_BEGIN_NAMESPACE
      namespace Ui { class Widget; }
      QT_END_NAMESPACE
      
      class Widget : public QWidget
      {
          Q_OBJECT
      
      public:
          Widget(QWidget *parent = nullptr);
          ~Widget();
          QLCDNumber    *rebootTimeLcdNum;
          QTimer *mtimer;
      
      private:
          Ui::Widget *ui;
          QPushButton *startButton;
          //QLCDNumber    *rebootTimeLcdNum;
          //QTimer *mtimer;
          //int a;
      
      private slots:
          void on_startButton_clicked();
          void onTimerTimeout();
      };
      
      
      Widget::Widget(QWidget *parent)
          : QWidget(parent)
          , ui(new Ui::Widget)
      {
          ui->setupUi(this);
          connect(startButton, SIGNAL(clicked()), this, SLOT(on_startButton_clicked()));
       } 
      

      I use gdb to debug and find that the fault occurred when connecting the slot function on_startButton_clicked() . And the fault won't occur if I put the member to public.

      Does anyone experencd the same problem?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Hupe You did not assign a valid pointer to startButton

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • HupeH Offline
        HupeH Offline
        Hupe
        wrote on last edited by
        #3

        Thanks! Is there any advice on how to assign a valid pointer or some textbooks to refer to?

        JonBJ jsulmJ 2 Replies Last reply
        0
        • HupeH Hupe

          Thanks! Is there any advice on how to assign a valid pointer or some textbooks to refer to?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Hupe
          You don't need a textbook to refer to, you need to assign your startButton to whatever button you have which you are wanting to attach the signal/slot to!

          1 Reply Last reply
          0
          • HupeH Hupe

            Thanks! Is there any advice on how to assign a valid pointer or some textbooks to refer to?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Hupe This belongs to absolute basics of C++. Do you know how memory is allocated in C++ using "new"?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • HupeH Offline
              HupeH Offline
              Hupe
              wrote on last edited by
              #6

              I found setupUi(QWidget *Widget) in ui_widget.h has already new the button. And it works well if there is only one private member *startButton.

              JonBJ 1 Reply Last reply
              0
              • HupeH Hupe

                I found setupUi(QWidget *Widget) in ui_widget.h has already new the button. And it works well if there is only one private member *startButton.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @Hupe
                You need to attach the signal to the button defined in the Designer. But it sounds/looks like you are declaring some new QPushButton *startButton; in your Widget class, which is not the one from Designer? Why are you doing that?

                1 Reply Last reply
                2
                • HupeH Offline
                  HupeH Offline
                  Hupe
                  wrote on last edited by
                  #8

                  Thanks! I found the problem.

                  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