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
Qt 6.11 is out! See what's new in the release blog

segmentation fault

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

    @Milav So, you get that error here in MainWindow:

    ui->connect->setDisabled(true); 
    mosq = new qtmosq(id, true); // Is it here?
    int size = sizeof(*mosq);
    

    ?
    It should work.
    Are there any other warnings or errors?
    Try to do a complete rebuild: delete build directory, run qmake and build.

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

    @jsulm

    Hello

    Here i have send the link at where i download the example.

    Reference link

    jsulmJ 1 Reply Last reply
    0
    • MilavM Milav

      @jsulm

      Hello

      Here i have send the link at where i download the example.

      Reference link

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

      @Milav That example does exactly what I suggested you to do:

      ui->connect->setDisabled(true);
      
      mosq = new qtmosq(id, false); // HERE
      connect (mosq, SIGNAL(connectEnable()), this, SLOT(connectEnabled()));
      

      Did you try to build and run this example? If so - does it work?

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

      MilavM 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Milav That example does exactly what I suggested you to do:

        ui->connect->setDisabled(true);
        
        mosq = new qtmosq(id, false); // HERE
        connect (mosq, SIGNAL(connectEnable()), this, SLOT(connectEnabled()));
        

        Did you try to build and run this example? If so - does it work?

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

        @jsulm

        Yes i delete the build directory and again i rebuild the whole project but i couldn't run the example. it is not work.

        jsulmJ 1 Reply Last reply
        0
        • MilavM Milav

          @jsulm

          Yes i delete the build directory and again i rebuild the whole project but i couldn't run the example. it is not work.

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

          @Milav said in segmentation fault:

          it is not work

          What exactly does this mean? Doesn't build? Crashes? Does not do what it should? ...?

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

          MilavM 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Milav said in segmentation fault:

            it is not work

            What exactly does this mean? Doesn't build? Crashes? Does not do what it should? ...?

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

            @jsulm

            it means build successful.

            but it is not run, it is crashes application.

            means while running the application, the application are crash.

            with following error.

            "segmentation fault"

            and i debug the application via qDebug(), the application are crash on following line of code.

            mosq->subscribe(NULL, "sensors/temprature", 1); // Segmentation falut
            
            J.HilkJ 1 Reply Last reply
            0
            • MilavM Milav

              @jsulm

              it means build successful.

              but it is not run, it is crashes application.

              means while running the application, the application are crash.

              with following error.

              "segmentation fault"

              and i debug the application via qDebug(), the application are crash on following line of code.

              mosq->subscribe(NULL, "sensors/temprature", 1); // Segmentation falut
              
              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #17

              @Milav well, did you press connect before you pressed subscribe?

              If not it will crash...


              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.

              MilavM 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @Milav well, did you press connect before you pressed subscribe?

                If not it will crash...

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

                @J-Hilk

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

                but it is crash...

                jsulmJ 1 Reply Last reply
                0
                • MilavM Milav

                  @jsulm

                  when i build the project it give me only warning like follow.

                  /home/tdp0009/Teq_Projects/Aug_2019/HMI/Firmware/QT/12_oct_hmi/qt-mosquitto-master/qtmosq.h:14: warning: 'mosqpp::mosquittopp::mosquittopp(const char*, bool)' is deprecated (declared at ../../../../CC_Lib/mosquitto/phytec_wega_build_websockets/usr/local/include/mosquittopp.h:94) [-Wdeprecated-declarations]
                  
                  /home/tdp0009/Teq_Projects/Aug_2019/HMI/Firmware/QT/12_oct_hmi/qt-mosquitto-master/mainwindow.cpp:57: warning: 'int mosqpp::mosquittopp::connect_async(const char*, int, int)' is deprecated (declared at ../../../../CC_Lib/mosquitto/phytec_wega_build_websockets/usr/local/include/mosquittopp.h:103) [-Wdeprecated-declarations]
                  
                  /home/tdp0009/Teq_Projects/Aug_2019/HMI/Firmware/QT/12_oct_hmi/qt-mosquitto-master/mainwindow.cpp:80: warning: 'int mosqpp::mosquittopp::subscribe(int*, const char*, int)' is deprecated (declared at ../../../../CC_Lib/mosquitto/phytec_wega_build_websockets/usr/local/include/mosquittopp.h:110) [-Wdeprecated-declarations]
                  

                  but i face segmentation fault error when i run that project, an i found the line at where i face segmentation fault.

                  it is ...

                  mosq->subscribe(NULL, "sensors/temprature", 1); // Segmentation falut
                  
                  M Offline
                  M Offline
                  mvuori
                  wrote on last edited by
                  #19

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

                  MilavM 1 Reply Last reply
                  0
                  • MilavM Milav

                    @J-Hilk

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

                    but it is crash...

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 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

                    MilavM 1 Reply Last reply
                    0
                    • jsulmJ jsulm

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

                      MilavM Offline
                      MilavM Offline
                      Milav
                      wrote on 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.

                      jsulmJ 1 Reply Last reply
                      0
                      • M mvuori

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

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

                        @mvuori

                        no it is supposed to be sensors/temprature.

                        1 Reply Last reply
                        0
                        • MilavM Milav

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

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 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

                          MilavM JonBJ 2 Replies Last reply
                          0
                          • jsulmJ jsulm

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

                            MilavM Offline
                            MilavM Offline
                            Milav
                            wrote on 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?

                            JonBJ 1 Reply Last reply
                            0
                            • jsulmJ jsulm

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

                              JonBJ Online
                              JonBJ Online
                              JonB
                              wrote on 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.

                              MilavM 1 Reply Last reply
                              0
                              • JonBJ JonB

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

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

                                @JonB

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

                                qtmosq(0xac50b0)

                                1 Reply Last reply
                                0
                                • MilavM Milav

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

                                  JonBJ Online
                                  JonBJ Online
                                  JonB
                                  wrote on 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.

                                  jsulmJ MilavM 2 Replies Last reply
                                  1
                                  • 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.

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 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

                                    JonBJ 1 Reply Last reply
                                    1
                                    • 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 Online
                                      JonBJ Online
                                      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

                                          • Login

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