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
Forum Update on Tuesday, May 27th 2025

segmentation fault

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qt 4.8cross-compilingarmv7mqtt
61 Posts 6 Posters 24.7k 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.
  • jsulmJ jsulm

    @JonB said in segmentation fault:

    I'm not sure this is actually trying to deference the pointer

    It does not, but I wanted to see its value :-)
    Looks like it's not NULL.

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

    @jsulm
    Indeedy :) So now let's see how qDebug() << *mosq fares?

    MilavM 1 Reply Last reply
    0
    • JonBJ JonB

      @Milav

      when i execute "qDebug() << mosq;" it gives following output.
      qtmosq(0xac50b0)

      I'm not sure this is actually trying to deference the pointer, it may just print its value. I would try something likeqDebug() << mosq->something;, where something is some field you know is supposed to exist & be valid in a qtmosq. Or try qDebug() << *mosq (note the *)?

      how i see stack trace in qt?
      can you please explore me more about stack trace?

      I don't know how you run in your "Embedded Custom Board", but can you run the app from inside a debugger? then when it seg faults you will see a "stack trace" in the debugger showing the call stack when the fault occurred.

      MilavM Offline
      MilavM Offline
      Milav
      wrote on last edited by
      #30

      @JonB said in segmentation fault:

      qDebug() << *mosq

      gives error :-

      /home/tdp0009/Teq_Projects/Aug_2019/HMI/Firmware/QT/12_oct_hmi/qt-mosquitto-master/mainwindow.cpp:54: note:   'qtmosq' is not derived from 'const QFlags<T>'
      

      @JonB said in segmentation fault:

      qDebug() << mosq->something

      i tried following things and it output are '0'.

      1. qDebug() << mosq->connect_async(host.data(), port);
      2. qDebug() << mosq->loop_start();
      3. qDebug() << mosq->subscribe(NULL, "sensors/temprature", 1);

      the output of all above command are zero (0).

      @JonB said in segmentation fault:

      app from inside a debugge

      i am not able to run the debugger because it gives following error.

      The inferior stopped because it received a signal from the Operating System.
      
      Signal name : 
      SIGILL
      Signal meaning : 
      Illegal instruction
      
      

      hope you got your answer.

      JonBJ 1 Reply Last reply
      0
      • JonBJ JonB

        @jsulm
        Indeedy :) So now let's see how qDebug() << *mosq fares?

        MilavM Offline
        MilavM Offline
        Milav
        wrote on last edited by
        #31

        @JonB said in segmentation fault:

        @jsulm
        Indeedy :) So now let's see how qDebug() << *mosq fares?

        sorry the error is as following not previous one.

        /home/tdp0009/Teq_Projects/Aug_2019/HMI/Firmware/QT/12_oct_hmi/qt-mosquitto-master/mainwindow.cpp:54: error: no match for 'operator<<' in 'qDebug()() << *((MainWindow*)this)->MainWindow::mosq'
        
        MilavM 1 Reply Last reply
        0
        • MilavM Milav

          @JonB said in segmentation fault:

          qDebug() << *mosq

          gives error :-

          /home/tdp0009/Teq_Projects/Aug_2019/HMI/Firmware/QT/12_oct_hmi/qt-mosquitto-master/mainwindow.cpp:54: note:   'qtmosq' is not derived from 'const QFlags<T>'
          

          @JonB said in segmentation fault:

          qDebug() << mosq->something

          i tried following things and it output are '0'.

          1. qDebug() << mosq->connect_async(host.data(), port);
          2. qDebug() << mosq->loop_start();
          3. qDebug() << mosq->subscribe(NULL, "sensors/temprature", 1);

          the output of all above command are zero (0).

          @JonB said in segmentation fault:

          app from inside a debugge

          i am not able to run the debugger because it gives following error.

          The inferior stopped because it received a signal from the Operating System.
          
          Signal name : 
          SIGILL
          Signal meaning : 
          Illegal instruction
          
          

          hope you got your answer.

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

          @Milav
          First you wrote

          and i debug the application via qDebug(), the application are crash on following line of code.
          mosq->subscribe(NULL, "sensors/temprature", 1); // Segmentation falut

          Now you write

          qDebug() << mosq->subscribe(NULL, "sensors/temprature", 1);
          the output of all above command are zero (0).

          This is a problem if you say sometimes it seg faults and sometimes it returns 0? Is that the case? You need to be very specific in your answers!

          i am not able to run the debugger because it gives following error.

          That is indeed a big problem. There is little for us to answer from what you have posted. Is a debugger supposed to work for your "Embedded Custom Board" (I don't know about this)? You really need one. Otherwise you are likely to have to try printing out all sorts of information in your code to try to diagnose what is going on....

          1 Reply Last reply
          0
          • MilavM Milav

            @JonB said in segmentation fault:

            @jsulm
            Indeedy :) So now let's see how qDebug() << *mosq fares?

            sorry the error is as following not previous one.

            /home/tdp0009/Teq_Projects/Aug_2019/HMI/Firmware/QT/12_oct_hmi/qt-mosquitto-master/mainwindow.cpp:54: error: no match for 'operator<<' in 'qDebug()() << *((MainWindow*)this)->MainWindow::mosq'
            
            MilavM Offline
            MilavM Offline
            Milav
            wrote on last edited by
            #33

            Screenshot from 2019-10-15 13-03-18.png

            jsulmJ 1 Reply Last reply
            0
            • MilavM Milav

              Screenshot from 2019-10-15 13-03-18.png

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

              @Milav Forget about

              qDebug() << *mosq;
              

              it's only going to work if operator<< was overloaded for that class, apparently it isn't, but this is not an issue.
              Can you try to run the app directly with gdb?

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

              JonBJ MilavM 2 Replies Last reply
              1
              • jsulmJ jsulm

                @Milav Forget about

                qDebug() << *mosq;
                

                it's only going to work if operator<< was overloaded for that class, apparently it isn't, but this is not an issue.
                Can you try to run the app directly with gdb?

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

                @jsulm

                Can you try to run the app directly with gdb?

                I know this is not the place for a long explanation. But when OP says

                I make a qt application for Embedded Custom Board

                I thought (knowing nothing about this) it meant he is doing something like )cross-)compiling of whatever but the app runs "on the board", so he might not have/be able to use a debugger? Can you explain to me in one sentence what the OP's enthronement actually is, I'd like to have the vaguest understanding....

                1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Milav Forget about

                  qDebug() << *mosq;
                  

                  it's only going to work if operator<< was overloaded for that class, apparently it isn't, but this is not an issue.
                  Can you try to run the app directly with gdb?

                  MilavM Offline
                  MilavM Offline
                  Milav
                  wrote on last edited by
                  #36

                  @jsulm said in segmentation fault:

                  Forget about
                  qDebug() << *mosq;

                  okay thank you.

                  @jsulm said in segmentation fault:

                  Can you try to run the app directly with gdb?

                  yes i tried but , debugger give me error,

                  the error is shown in below image.

                  Screenshot from 2019-10-15 13-11-13.png

                  JonBJ J.HilkJ 2 Replies Last reply
                  0
                  • MilavM Milav

                    @jsulm said in segmentation fault:

                    Forget about
                    qDebug() << *mosq;

                    okay thank you.

                    @jsulm said in segmentation fault:

                    Can you try to run the app directly with gdb?

                    yes i tried but , debugger give me error,

                    the error is shown in below image.

                    Screenshot from 2019-10-15 13-11-13.png

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

                    @Milav
                    I think @jsulm is asking you try running your app directly in gdb (from the command-line), not from within Qt Creator, as Creator might be the cause of your debugger problem.

                    MilavM 1 Reply Last reply
                    0
                    • MilavM Milav

                      @jsulm said in segmentation fault:

                      Forget about
                      qDebug() << *mosq;

                      okay thank you.

                      @jsulm said in segmentation fault:

                      Can you try to run the app directly with gdb?

                      yes i tried but , debugger give me error,

                      the error is shown in below image.

                      Screenshot from 2019-10-15 13-11-13.png

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #38

                      @Milav ok, since you're able to run the debugger from QtCreator, try the following, select Debugin the menu bar, and select Start and Break on main that should work, and then step through your code line by line.


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @Milav
                        I think @jsulm is asking you try running your app directly in gdb (from the command-line), not from within Qt Creator, as Creator might be the cause of your debugger problem.

                        MilavM Offline
                        MilavM Offline
                        Milav
                        wrote on last edited by
                        #39

                        @JonB said in segmentation fault:

                        app directly in gdb (from the command-line)

                        actually, i am new in this.

                        give me some time i explore it and give you answer.

                        i don't know how i run app in gdb.

                        JonBJ 1 Reply Last reply
                        0
                        • MilavM Milav

                          @JonB said in segmentation fault:

                          app directly in gdb (from the command-line)

                          actually, i am new in this.

                          give me some time i explore it and give you answer.

                          i don't know how i run app in gdb.

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

                          @Milav

                          1. Open Command Prompt/terminal/shell.
                          2. cd to where your executable is.
                          3. gdb <your-executable>
                          MilavM 1 Reply Last reply
                          1
                          • JonBJ JonB

                            @Milav

                            1. Open Command Prompt/terminal/shell.
                            2. cd to where your executable is.
                            3. gdb <your-executable>
                            MilavM Offline
                            MilavM Offline
                            Milav
                            wrote on last edited by
                            #41

                            @JonB

                            but in gdb how i see "stack trace" ?

                            what classes i use from List of classes of commands?

                            please tell me

                            jsulmJ 1 Reply Last reply
                            0
                            • MilavM Milav

                              @JonB

                              but in gdb how i see "stack trace" ?

                              what classes i use from List of classes of commands?

                              please tell me

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

                              @Milav In gdb enter bt and press enter after your app crashed

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

                              MilavM 1 Reply Last reply
                              0
                              • jsulmJ jsulm

                                @Milav In gdb enter bt and press enter after your app crashed

                                MilavM Offline
                                MilavM Offline
                                Milav
                                wrote on last edited by
                                #43

                                @jsulm

                                i enter the gdb command as following .

                                tdp0009@tdp0009-desktop:~/Teq_Projects/Aug_2019/HMI/Firmware/QT/Desktop_Application/11-oct/qt-mqtt-example/build-qt-mosquitto-Desktop-Release$ gdb qt-mosquitto 
                                GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
                                Copyright (C) 2016 Free Software Foundation, Inc.
                                License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
                                This is free software: you are free to change and redistribute it.
                                There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
                                and "show warranty" for details.
                                This GDB was configured as "x86_64-linux-gnu".
                                Type "show configuration" for configuration details.
                                For bug reporting instructions, please see:
                                <http://www.gnu.org/software/gdb/bugs/>.
                                Find the GDB manual and other documentation resources online at:
                                <http://www.gnu.org/software/gdb/documentation/>.
                                For help, type "help".
                                Type "apropos word" to search for commands related to "word"...
                                Reading symbols from qt-mosquitto...(no debugging symbols found)...done.
                                (gdb) bt
                                No stack.
                                (gdb) 
                                No stack.
                                (gdb)
                                
                                JonBJ 1 Reply Last reply
                                0
                                • MilavM Milav

                                  @jsulm

                                  i enter the gdb command as following .

                                  tdp0009@tdp0009-desktop:~/Teq_Projects/Aug_2019/HMI/Firmware/QT/Desktop_Application/11-oct/qt-mqtt-example/build-qt-mosquitto-Desktop-Release$ gdb qt-mosquitto 
                                  GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
                                  Copyright (C) 2016 Free Software Foundation, Inc.
                                  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
                                  This is free software: you are free to change and redistribute it.
                                  There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
                                  and "show warranty" for details.
                                  This GDB was configured as "x86_64-linux-gnu".
                                  Type "show configuration" for configuration details.
                                  For bug reporting instructions, please see:
                                  <http://www.gnu.org/software/gdb/bugs/>.
                                  Find the GDB manual and other documentation resources online at:
                                  <http://www.gnu.org/software/gdb/documentation/>.
                                  For help, type "help".
                                  Type "apropos word" to search for commands related to "word"...
                                  Reading symbols from qt-mosquitto...(no debugging symbols found)...done.
                                  (gdb) bt
                                  No stack.
                                  (gdb) 
                                  No stack.
                                  (gdb)
                                  
                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by JonB
                                  #44

                                  @Milav
                                  Type run first to run your program! Then if it crashes type bt. You could type man gdb from the command-line, or help from within gdb like the message states. We had to learn to do that....

                                  MilavM 1 Reply Last reply
                                  1
                                  • JonBJ JonB

                                    @Milav
                                    Type run first to run your program! Then if it crashes type bt. You could type man gdb from the command-line, or help from within gdb like the message states. We had to learn to do that....

                                    MilavM Offline
                                    MilavM Offline
                                    Milav
                                    wrote on last edited by
                                    #45

                                    @JonB

                                    thank you for your help.

                                    i run gdb from development host machine.

                                    here i send the output of that.

                                    tdp0009@tdp0009-desktop:~/Teq_Projects/Aug_2019/HMI/Phytec_Toolchain/arm-cortexa8-linux-gnueabihf/bin$ ./arm-cortexa8-linux-gnueabihf-gdb
                                    GNU gdb (GDB) 7.5
                                    Copyright (C) 2012 Free Software Foundation, Inc.
                                    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
                                    This is free software: you are free to change and redistribute it.
                                    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
                                    and "show warranty" for details.
                                    This GDB was configured as "--host=i686-host-linux-gnu --target=arm-cortexa8-linux-gnueabihf".
                                    For bug reporting instructions, please see:
                                    <http://www.gnu.org/software/gdb/bugs/>.
                                    (gdb) target extended 192.168.5.52:2345
                                    Remote debugging using 192.168.5.52:2345
                                    (gdb) set remote exec-file /opt/milav/qt-mosquitto
                                    (gdb) run
                                    Starting program:  
                                    
                                    Program received signal SIGILL, Illegal instruction.
                                    0x404df208 in ?? ()
                                    (gdb) bt
                                    #0  0x404df208 in ?? ()
                                    Cannot access memory at address 0x0
                                    #1  0x404092c0 in ?? ()
                                    Cannot access memory at address 0x0
                                    #2  0x404092c0 in ?? ()
                                    Cannot access memory at address 0x0
                                    Backtrace stopped: previous frame identical to this frame (corrupt stack?)
                                    (gdb) 
                                    

                                    i think you got what you want.

                                    looking forward hearing from you.

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • MilavM Milav

                                      @JonB

                                      thank you for your help.

                                      i run gdb from development host machine.

                                      here i send the output of that.

                                      tdp0009@tdp0009-desktop:~/Teq_Projects/Aug_2019/HMI/Phytec_Toolchain/arm-cortexa8-linux-gnueabihf/bin$ ./arm-cortexa8-linux-gnueabihf-gdb
                                      GNU gdb (GDB) 7.5
                                      Copyright (C) 2012 Free Software Foundation, Inc.
                                      License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
                                      This is free software: you are free to change and redistribute it.
                                      There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
                                      and "show warranty" for details.
                                      This GDB was configured as "--host=i686-host-linux-gnu --target=arm-cortexa8-linux-gnueabihf".
                                      For bug reporting instructions, please see:
                                      <http://www.gnu.org/software/gdb/bugs/>.
                                      (gdb) target extended 192.168.5.52:2345
                                      Remote debugging using 192.168.5.52:2345
                                      (gdb) set remote exec-file /opt/milav/qt-mosquitto
                                      (gdb) run
                                      Starting program:  
                                      
                                      Program received signal SIGILL, Illegal instruction.
                                      0x404df208 in ?? ()
                                      (gdb) bt
                                      #0  0x404df208 in ?? ()
                                      Cannot access memory at address 0x0
                                      #1  0x404092c0 in ?? ()
                                      Cannot access memory at address 0x0
                                      #2  0x404092c0 in ?? ()
                                      Cannot access memory at address 0x0
                                      Backtrace stopped: previous frame identical to this frame (corrupt stack?)
                                      (gdb) 
                                      

                                      i think you got what you want.

                                      looking forward hearing from you.

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

                                      @Milav said in segmentation fault:

                                      i think you got what you want

                                      Not really.
                                      Did you build the app in debug mode?

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

                                      MilavM 1 Reply Last reply
                                      0
                                      • jsulmJ jsulm

                                        @Milav said in segmentation fault:

                                        i think you got what you want

                                        Not really.
                                        Did you build the app in debug mode?

                                        MilavM Offline
                                        MilavM Offline
                                        Milav
                                        wrote on last edited by
                                        #47

                                        @jsulm said in segmentation fault:

                                        Did you build the app in debug mode?

                                        yes i build the app in debug mode.

                                        1 Reply Last reply
                                        0
                                        • MilavM Milav

                                          Hello,

                                          I make a qt application for Embedded Custom Board and when i run the Application it gives segmentation fault.

                                          The application give segmentation fault due to following line.

                                            mosq->subscribe(mosq->getMID(), topic.data(), 1);
                                          

                                          where mosq is define and declare as follow.

                                          class MainWindow : public QMainWindow
                                          {
                                              Q_OBJECT
                                          
                                          public:
                                              explicit MainWindow(QWidget *parent = 0);
                                              ~MainWindow();
                                          
                                          private:
                                              qtmosq* mosq = NULL;
                                              QStringList subed;
                                              QString currentTopic;
                                              Ui::MainWindow *ui;
                                          --------
                                          --------
                                          --------
                                          };
                                          

                                          where qtmosq is define as follow..

                                          #include "QObject"
                                          #include "mosquittopp.h"
                                          
                                          using namespace mosqpp;
                                          
                                          class qtmosq : public QObject, public mosquittopp
                                          {
                                              Q_OBJECT
                                          
                                          public:
                                              qtmosq(const char *id = NULL, bool clean_session = true) : mosquittopp (id, clean_session) {MID = 0;}
                                              ~qtmosq() {}
                                          
                                              void on_connect(int result)
                                              {
                                                  if (!result)
                                                  {
                                                      //subscribe(NULL, "$SYS/#", 2);
                                                      emit connected();
                                                  }
                                                  else
                                                      emit connectEnable();
                                              }
                                              void on_publish(int id)
                                              {
                                                  MID++;
                                                  emit messageSent(true);
                                              }
                                              void on_subscribe(int mid, int qos_count, const int *granted_qos)
                                              {
                                                  if (MID != 0)
                                                      emit subscribed();
                                                  MID++;
                                              }
                                          ..........
                                          ..........
                                          ..........
                                          
                                          signals:
                                              void connected();
                                              void messageSent(bool);
                                              void messageReceived(QString);
                                              void connectEnable();
                                              void subscribed();
                                          };
                                          

                                          so what is the reason behind for this fault.

                                          The same application are successfully run on Host Linux PC.

                                          I have use same mosquitto library in both the test.

                                          please help me to sort out this problem.

                                          I have send the reference link at where i used above program.

                                          Link :- Ref. Link

                                          Thank you
                                          Milav Soni

                                          Pablo J. RoginaP Offline
                                          Pablo J. RoginaP Offline
                                          Pablo J. Rogina
                                          wrote on last edited by
                                          #48

                                          @Milav said in segmentation fault:

                                          Link :- Ref. Link

                                          Could it be possible that you run such example AS IS, I mean just download/clone the code and try such example without any change.
                                          If you manage to make it work, then you'll have the foundation to start adapting it to whatever you need/desire.

                                          In addition, is there any compelling reason not to use the Qt MQTT module?
                                          Have you try any of the Qt MQTT examples?

                                          Upvote the answer(s) that helped you solve the issue
                                          Use "Topic Tools" button to mark your post as Solved
                                          Add screenshots via postimage.org
                                          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                                          MilavM 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