Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Serial problem , segmentation fault
QtWS25 Last Chance

Serial problem , segmentation fault

Scheduled Pinned Locked Moved QML and Qt Quick
serialarduinosignalsisegv
10 Posts 4 Posters 4.2k 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.
  • D Offline
    D Offline
    domcsidd
    wrote on 20 Mar 2015, 21:04 last edited by
    #1

    Hi everyone!
    I am new here , and i am working on my first Qt Project . I have some problem with my code. There is something with my write() function. When i start debugging , the compiler give an "Segmentation fault"msg. I can' imagine what can be the problem . I stared the code for hours , but still not found the answer... I know it is not a good method to copy all of my code, but i have no idea , where is the bug.

    Here is my Project : https://drive.google.com/folderview?id=0B7daYRiQ-gLoblVackg4WnFySjQ&usp=sharing

    PLS , help me :)

    S 1 Reply Last reply 21 Mar 2015, 13:45
    0
    • K Offline
      K Offline
      koahnig
      wrote on 20 Mar 2015, 21:24 last edited by
      #2

      Welcome to devnet

      Did you familiarize yourself already with the debugger?

      You should be able to get to the line step by step until your application is crashing. When you have located your problem, you can post mostly a few lines. That is probably a better way to get help.

      Vote the answer(s) that helped you to solve your issue(s)

      D 1 Reply Last reply 20 Mar 2015, 21:30
      0
      • K koahnig
        20 Mar 2015, 21:24

        Welcome to devnet

        Did you familiarize yourself already with the debugger?

        You should be able to get to the line step by step until your application is crashing. When you have located your problem, you can post mostly a few lines. That is probably a better way to get help.

        D Offline
        D Offline
        domcsidd
        wrote on 20 Mar 2015, 21:30 last edited by
        #3

        @koahnig

        Thanks for your reply .
        I tried it several times ... And the lines , which are may cause the problem are from a tutorial. I have compiled the project of the tutorial , but it is ok , the tutorial's code works fine . And the same code is not working in my Project, but the logic is the same . So this is why i am here .

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 20 Mar 2015, 23:25 last edited by
          #4

          Hi and welcome to devnet,

          Then which line exactly does the debugger show ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply 21 Mar 2015, 08:13
          0
          • S SGaist
            20 Mar 2015, 23:25

            Hi and welcome to devnet,

            Then which line exactly does the debugger show ?

            D Offline
            D Offline
            domcsidd
            wrote on 21 Mar 2015, 08:13 last edited by
            #5

            @SGaist

            This is all the error message what i see : https://drive.google.com/file/d/0B7daYRiQ-gLoM2c5X2JXbVRldFE/view?usp=sharing

            But if i am not call the lUpdate func , the program start.

            K 1 Reply Last reply 21 Mar 2015, 10:45
            0
            • D domcsidd
              21 Mar 2015, 08:13

              @SGaist

              This is all the error message what i see : https://drive.google.com/file/d/0B7daYRiQ-gLoM2c5X2JXbVRldFE/view?usp=sharing

              But if i am not call the lUpdate func , the program start.

              K Offline
              K Offline
              koahnig
              wrote on 21 Mar 2015, 10:45 last edited by
              #6

              @domcsidd
              Looks like the ardunio pointer has not been initialized.
              In the right pane of the debugger window you have posted, you can click on the little triangle left of "this". You will see all variables of your instance listed. You will probably see also "ardunio" and the value "0x000".

              At least that is my expectation. Check it out.

              Note. it depends where ardunio is declare and you may have to dig a bit further.

              Vote the answer(s) that helped you to solve your issue(s)

              D 1 Reply Last reply 21 Mar 2015, 12:21
              0
              • K koahnig
                21 Mar 2015, 10:45

                @domcsidd
                Looks like the ardunio pointer has not been initialized.
                In the right pane of the debugger window you have posted, you can click on the little triangle left of "this". You will see all variables of your instance listed. You will probably see also "ardunio" and the value "0x000".

                At least that is my expectation. Check it out.

                Note. it depends where ardunio is declare and you may have to dig a bit further.

                D Offline
                D Offline
                domcsidd
                wrote on 21 Mar 2015, 12:21 last edited by
                #7

                @koahnig

                Thank you very much!
                But i still didn't find the solution. The arduino pointer is declarated in the mainwindow.h header . Like this "QSerialPort *arduino;" . The arduino adress/value is "0x0". But all the other arduino func works... I would be happy , if you could offer an other way to write integer to the serial.

                K 1 Reply Last reply 21 Mar 2015, 13:43
                0
                • D domcsidd
                  21 Mar 2015, 12:21

                  @koahnig

                  Thank you very much!
                  But i still didn't find the solution. The arduino pointer is declarated in the mainwindow.h header . Like this "QSerialPort *arduino;" . The arduino adress/value is "0x0". But all the other arduino func works... I would be happy , if you could offer an other way to write integer to the serial.

                  K Offline
                  K Offline
                  koahnig
                  wrote on 21 Mar 2015, 13:43 last edited by
                  #8

                  @domcsidd
                  Sorry, at least you know that the arduino pointer is a null pointer. It is either never initialized (memory assigned) or it has been set unintensionally to zero.

                  You need to check all assignments to arduino. With the debugger you can go step by step through your code and check where the problem may start.

                  If your code is still similar to what you have initially posted, you can step into the constructor of MainWindow there is the initial assignment of

                  arduino = new QSerialPort; 
                  

                  At this point there should be a value assigned. Best is to set a breakpoint before and after. Check whether the value is as expected.

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  0
                  • D domcsidd
                    20 Mar 2015, 21:04

                    Hi everyone!
                    I am new here , and i am working on my first Qt Project . I have some problem with my code. There is something with my write() function. When i start debugging , the compiler give an "Segmentation fault"msg. I can' imagine what can be the problem . I stared the code for hours , but still not found the answer... I know it is not a good method to copy all of my code, but i have no idea , where is the bug.

                    Here is my Project : https://drive.google.com/folderview?id=0B7daYRiQ-gLoblVackg4WnFySjQ&usp=sharing

                    PLS , help me :)

                    S Offline
                    S Offline
                    SysTech
                    wrote on 21 Mar 2015, 13:45 last edited by SysTech
                    #9

                    @domcsidd said:

                    Hi everyone!
                    I am new here , and i am working on my first Qt Project . I have some problem with my code. There is something with my write() function. When i start debugging , the compiler give an "Segmentation fault"msg. I can' imagine what can be the problem . I stared the code for hours , but still not found the answer... I know it is not a good method to copy all of my code, but i have no idea , where is the bug.

                    Here is my Project : https://drive.google.com/folderview?id=0B7daYRiQ-gLoblVackg4WnFySjQ&usp=sharing

                    PLS , help me :)

                    Hi! Often staring at the code for hours really doesn't help. You just see the same bug and keep thinking its just fine.

                    You give a hint that the arduino pointer address is 0x0. Thats not good. It should have a value so first question is:

                    Are you somewhere saying:

                    arduino = new QSerialPort(this);
                    

                    If not then most likely that is your problem. The fact that some routines do work with a 0x0 pointer is just luck and alignment. Also some routines might be static and will work ok.

                    I have several pieces of advice:

                    1. Try to post more example code here. Try to limit what you post to what you know actually runs BEFORE the error. No one here can page through a lot of code to help you find your bug. So you need to show us "it runs this module just fine..." "then it calls this routine..." "next this one" and people will take a look and see if they can help.

                    2. Usually problems like this are related either to unallocated pointers or pointers that get tromped on by some other code. It is not 100% clear from your screen pict if the arduino pointer is the problem or not. But since the debugger was on that line I think it could be likely. So... put in break points throughout your program and follow arduino around. When you first create arduino make a note of the hex address in the debugger. Then follow it through your various places and see if it changes at all.

                    Last piece of device is that few programmers in this world can debug a 10,000 or more line program at once. We all need to chunk things into smaller pieces. Eliminate running code and focus on the problem area. Sometime to fine the problem area is more than 1/2 of the battle.

                    I use qDebug() a lot for this purpose. If I'm getting a crash I run around and deposit some qDebug() messages with unique output something simple like "A" "B" "B1" "B2" etc. Then if the program crashes and the output is: "A" "B" "B1" then I know to start looking in the area after B1 but before B2.

                    This does not guarantee the problem did not occur in B or even A but at least you can focus on a smaller portion of your code at first and work backward.

                    1 Reply Last reply
                    1
                    • D Offline
                      D Offline
                      domcsidd
                      wrote on 21 Mar 2015, 20:07 last edited by domcsidd
                      #10

                      Oh yeah :) ! Finally i have found the bug . The problem was the Load() func. it was before the ,,arduino = new QSerialPort ;" . Thanks for all of the help :) !!!

                      1 Reply Last reply
                      0

                      10/10

                      21 Mar 2015, 20:07

                      • Login

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