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 Monday, May 27th 2025

segmentation fault

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qt 4.8cross-compilingarmv7mqtt
61 Posts 6 Posters 24.7k 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.
  • M Milav
    15 Oct 2019, 06:05

    @J-Hilk

    I press first Connect button and than after i press subscribed button.

    but it is crash...

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 15 Oct 2019, 06:10 last edited by
    #20

    @Milav Did you debug to see whether mosq is not a nullptr? If it's not please provide stack trace after crash.
    Also, in connectPressed it does a return if port is not set - is it set if you press connect?
    You should really run through debugger...

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

    M 1 Reply Last reply 15 Oct 2019, 06:28
    0
    • J jsulm
      15 Oct 2019, 06:10

      @Milav Did you debug to see whether mosq is not a nullptr? If it's not please provide stack trace after crash.
      Also, in connectPressed it does a return if port is not set - is it set if you press connect?
      You should really run through debugger...

      M Offline
      M Offline
      Milav
      wrote on 15 Oct 2019, 06:28 last edited by
      #21

      @jsulm

      i debug the size of mosq pointer through following code.

       int size = sizeof(*mosq);
          qDebug() << size;
      

      and output is 20;

      and in connectpressed button slot are run succesfully.

      port value are shown correctly.

      when i run debugger it shows following error.

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

      hope you got my point.

      J 1 Reply Last reply 15 Oct 2019, 06:48
      0
      • M mvuori
        15 Oct 2019, 06:10

        If temprature is supposed to be temperature, this is a bug:
        mosq->subscribe(NULL, "sensors/temprature", 1);

        M Offline
        M Offline
        Milav
        wrote on 15 Oct 2019, 06:29 last edited by
        #22

        @mvuori

        no it is supposed to be sensors/temprature.

        1 Reply Last reply
        0
        • M Milav
          15 Oct 2019, 06:28

          @jsulm

          i debug the size of mosq pointer through following code.

           int size = sizeof(*mosq);
              qDebug() << size;
          

          and output is 20;

          and in connectpressed button slot are run succesfully.

          port value are shown correctly.

          when i run debugger it shows following error.

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

          hope you got my point.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 15 Oct 2019, 06:48 last edited by
          #23

          @Milav said in segmentation fault:

          i debug the size of mosq pointer through following code.

          The size of a pointer is fixed, it doesn't matter whether it contains nullptr or something else.
          Do

          qDebug() << mosq;
          

          instead to see the value of the pointer.
          Without stack trace I can't tell you what is going on...

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

          M J 2 Replies Last reply 15 Oct 2019, 07:14
          0
          • J jsulm
            15 Oct 2019, 06:48

            @Milav said in segmentation fault:

            i debug the size of mosq pointer through following code.

            The size of a pointer is fixed, it doesn't matter whether it contains nullptr or something else.
            Do

            qDebug() << mosq;
            

            instead to see the value of the pointer.
            Without stack trace I can't tell you what is going on...

            M Offline
            M Offline
            Milav
            wrote on 15 Oct 2019, 07:14 last edited by
            #24

            @jsulm

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

            qtmosq(0xac50b0)
            

            how i see stack trace in qt?

            can you please explore me more about stack trace?

            J 1 Reply Last reply 15 Oct 2019, 07:20
            0
            • J jsulm
              15 Oct 2019, 06:48

              @Milav said in segmentation fault:

              i debug the size of mosq pointer through following code.

              The size of a pointer is fixed, it doesn't matter whether it contains nullptr or something else.
              Do

              qDebug() << mosq;
              

              instead to see the value of the pointer.
              Without stack trace I can't tell you what is going on...

              J Offline
              J Offline
              JonB
              wrote on 15 Oct 2019, 07:16 last edited by
              #25

              @Milav

              int size = sizeof(*mosq);

              @jsulm

              The size of a pointer is fixed,

              A slight slip of the tongue there. I think what my colleague @jsulm meant to clarify is: sizeof(...) is a compile-time calculation, it does not matter what the value of mosq is or what it points at run-time, rather this statement just assigns sizeof(qtmosq) regardless. As he says, show us what is in the mosq.

              M 1 Reply Last reply 15 Oct 2019, 07:18
              0
              • J JonB
                15 Oct 2019, 07:16

                @Milav

                int size = sizeof(*mosq);

                @jsulm

                The size of a pointer is fixed,

                A slight slip of the tongue there. I think what my colleague @jsulm meant to clarify is: sizeof(...) is a compile-time calculation, it does not matter what the value of mosq is or what it points at run-time, rather this statement just assigns sizeof(qtmosq) regardless. As he says, show us what is in the mosq.

                M Offline
                M Offline
                Milav
                wrote on 15 Oct 2019, 07:18 last edited by
                #26

                @JonB

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

                qtmosq(0xac50b0)

                1 Reply Last reply
                0
                • M Milav
                  15 Oct 2019, 07:14

                  @jsulm

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

                  qtmosq(0xac50b0)
                  

                  how i see stack trace in qt?

                  can you please explore me more about stack trace?

                  J Offline
                  J Offline
                  JonB
                  wrote on 15 Oct 2019, 07:20 last edited by JonB
                  #27

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

                  J M 2 Replies Last reply 15 Oct 2019, 07:25
                  1
                  • J JonB
                    15 Oct 2019, 07:20

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

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 15 Oct 2019, 07:25 last edited by jsulm
                    #28

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

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

                    J 1 Reply Last reply 15 Oct 2019, 07:27
                    1
                    • J jsulm
                      15 Oct 2019, 07:25

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

                      J Offline
                      J Offline
                      JonB
                      wrote on 15 Oct 2019, 07:27 last edited by JonB
                      #29

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

                      M 1 Reply Last reply 15 Oct 2019, 07:32
                      0
                      • J JonB
                        15 Oct 2019, 07:20

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

                        M Offline
                        M Offline
                        Milav
                        wrote on 15 Oct 2019, 07:30 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.

                        J 1 Reply Last reply 15 Oct 2019, 07:34
                        0
                        • J JonB
                          15 Oct 2019, 07:27

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

                          M Offline
                          M Offline
                          Milav
                          wrote on 15 Oct 2019, 07:32 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'
                          
                          M 1 Reply Last reply 15 Oct 2019, 07:34
                          0
                          • M Milav
                            15 Oct 2019, 07: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.

                            J Offline
                            J Offline
                            JonB
                            wrote on 15 Oct 2019, 07:34 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
                            • M Milav
                              15 Oct 2019, 07:32

                              @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'
                              
                              M Offline
                              M Offline
                              Milav
                              wrote on 15 Oct 2019, 07:34 last edited by
                              #33

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

                              J 1 Reply Last reply 15 Oct 2019, 07:37
                              0
                              • M Milav
                                15 Oct 2019, 07:34

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

                                J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 15 Oct 2019, 07:37 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

                                J M 2 Replies Last reply 15 Oct 2019, 07:41
                                1
                                • J jsulm
                                  15 Oct 2019, 07:37

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

                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 15 Oct 2019, 07:41 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
                                  • J jsulm
                                    15 Oct 2019, 07:37

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

                                    M Offline
                                    M Offline
                                    Milav
                                    wrote on 15 Oct 2019, 07:41 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

                                    J J.HilkJ 2 Replies Last reply 15 Oct 2019, 07:43
                                    0
                                    • M Milav
                                      15 Oct 2019, 07:41

                                      @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 Offline
                                      J Offline
                                      JonB
                                      wrote on 15 Oct 2019, 07:43 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.

                                      M 1 Reply Last reply 15 Oct 2019, 08:39
                                      0
                                      • M Milav
                                        15 Oct 2019, 07:41

                                        @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 15 Oct 2019, 07:46 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
                                        • J JonB
                                          15 Oct 2019, 07:43

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

                                          M Offline
                                          M Offline
                                          Milav
                                          wrote on 15 Oct 2019, 08:39 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.

                                          J 1 Reply Last reply 15 Oct 2019, 08:41
                                          0

                                          29/61

                                          15 Oct 2019, 07:27

                                          • Login

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