Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt program crashes after some minutes run time!
Forum Updated to NodeBB v4.3 + New Features

Qt program crashes after some minutes run time!

Scheduled Pinned Locked Moved General and Desktop
20 Posts 4 Posters 4.7k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #7

    If it's that big, try running a tool like cppcheck to see if you missed something

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

    X 1 Reply Last reply
    0
    • SGaistS SGaist

      If it's that big, try running a tool like cppcheck to see if you missed something

      X Offline
      X Offline
      xmaze
      wrote on last edited by
      #8

      @SGaist runs this also at Linux?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SysTech
        wrote on last edited by
        #9

        It definitely sounds like you have a pointer that is getting trashed or a serious memory leak.

        One way to combat this would be tools to check memory use. However another and perhaps simpler approach is to litter your code with qDebug() calls with unique strings. Some times I just start doing things like:

        qDebug() << "A";

        ... some code ...

        qDebug << "B";

        etc...

        Try to figure out what the last thing printed is. Then work your way backward and set debug break points. At least using qDebug you can narrow the search area.

        X 1 Reply Last reply
        0
        • S SysTech

          It definitely sounds like you have a pointer that is getting trashed or a serious memory leak.

          One way to combat this would be tools to check memory use. However another and perhaps simpler approach is to litter your code with qDebug() calls with unique strings. Some times I just start doing things like:

          qDebug() << "A";

          ... some code ...

          qDebug << "B";

          etc...

          Try to figure out what the last thing printed is. Then work your way backward and set debug break points. At least using qDebug you can narrow the search area.

          X Offline
          X Offline
          xmaze
          wrote on last edited by
          #10

          @SysTech i made also this, but seems to be a problem at
          a.lon and a.lat.

          a is a structure
          i call this

              if(AirplanesVector.size()>0&&flightNameChoosed.size()>2) {
          int i = ReturnIndexOfSearch(flightNameChoosed);
          if(i>-1){
          aircraft a = AirplanesVector[i];
              qDebug()<<"LON: " << a.lon <<"LAT: " <<a.lat;
          

          And after a long time crashes.

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xmaze
            wrote on last edited by xmaze
            #11

            I made some changes and seems to be very stable now,

             aircraft *a = new aircraft[1];
                    a= &AirplanesVector[i];
             qDebug()<<"LON: " << a->lon <<"LAT: " <<a->lat;
             a=0;
            
            1 Reply Last reply
            0
            • Chris KawaC Online
              Chris KawaC Online
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by Chris Kawa
              #12

              You just created a memory leak.
              If anything it should be this:

              aircraft *a = &AirplanesVector[i];
              

              Previously you were making a copy, so it seems your aircraft type is buggy (no proper copy constructor/assignment operator?).

              X 1 Reply Last reply
              0
              • Chris KawaC Chris Kawa

                You just created a memory leak.
                If anything it should be this:

                aircraft *a = &AirplanesVector[i];
                

                Previously you were making a copy, so it seems your aircraft type is buggy (no proper copy constructor/assignment operator?).

                X Offline
                X Offline
                xmaze
                wrote on last edited by xmaze
                #13

                @Chris-Kawa but now it is working stable, the program don't crash, this is the aircraft structure from ramirez:

                struct aircraft {
                uint32_t addr;      /* ICAO address */
                char hexaddr[7];    /* Printable ICAO address */
                char flight[9];     /* Flight number */
                int altitude;       /* Altitude */
                int speed;          /* Velocity computed from EW and NS components. */
                int track;          /* Angle of flight. */
                time_t seen;        /* Time at which the last packet was received. */
                long messages;      /* Number of Mode S messages received. */
                /* Encoded latitude and longitude as extracted by odd and even
                 * CPR encoded messages. */
                int odd_cprlat;
                int odd_cprlon;
                int even_cprlat;
                int even_cprlon;
                double lat, lon;    /* Coordinated obtained from CPR encoded data. */
                long long odd_cprtime, even_cprtime;
                struct aircraft *next; /* Next aircraft in our linked list. */
                }; 
                

                this is my project https://github.com/ntosis/GUI_dump1090

                1 Reply Last reply
                0
                • Chris KawaC Online
                  Chris KawaC Online
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  Working stable but leaking memory. You have a new without a delete. It's not Java. It's a memory leak

                      aircraft *a = new aircraft[1];   //creates new instance, what for if you don't even use it?
                      a= &AirplanesVector[i]; //assigns to a some other instance, previous instance is now lost and leaked
                      ...
                      a=0; //this does not free any memory in c++
                  

                  You have a next pointer in your linked list structure. If you just copy it you are also copying that pointer. then you have two nodes in your list pointing to the same next item and this can lead to a double delete (crash) if not carefully handled.

                  Btw. keeping a linked list elements in a vector seems like an odd hing to do. Why not just make it a vector then?

                  1 Reply Last reply
                  0
                  • X Offline
                    X Offline
                    xmaze
                    wrote on last edited by
                    #15

                    if i use delete, then this line make the program to crash again, i understand what do you mean. i try to find a solution! this a code from an other developer so he has an other concept!

                    1 Reply Last reply
                    0
                    • Chris KawaC Online
                      Chris KawaC Online
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on last edited by
                      #16

                      Don't use delete cause you're deleting the wrong thing. Just don't create an extra instance. Do it like I posted before:

                      aircraft *a = &AirplanesVector[i]; 
                      qDebug()<<"LON: " << a->lon <<"LAT: " <<a->lat;
                      

                      That's it. No memory leak and no needless instances.

                      X 2 Replies Last reply
                      0
                      • Chris KawaC Chris Kawa

                        Don't use delete cause you're deleting the wrong thing. Just don't create an extra instance. Do it like I posted before:

                        aircraft *a = &AirplanesVector[i]; 
                        qDebug()<<"LON: " << a->lon <<"LAT: " <<a->lat;
                        

                        That's it. No memory leak and no needless instances.

                        X Offline
                        X Offline
                        xmaze
                        wrote on last edited by
                        #17

                        @Chris-Kawa thank you, now i run the program to see if its ok!

                        1 Reply Last reply
                        0
                        • Chris KawaC Chris Kawa

                          Don't use delete cause you're deleting the wrong thing. Just don't create an extra instance. Do it like I posted before:

                          aircraft *a = &AirplanesVector[i]; 
                          qDebug()<<"LON: " << a->lon <<"LAT: " <<a->lat;
                          

                          That's it. No memory leak and no needless instances.

                          X Offline
                          X Offline
                          xmaze
                          wrote on last edited by
                          #18

                          @Chris-Kawa

                          Hi again, the program runs stable until is going in backstage, if for example i open the Mozilla to surfing, then the program crashes!

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #19

                            Can your share the backtrace of your crash ?

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

                            X 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              Can your share the backtrace of your crash ?

                              X Offline
                              X Offline
                              xmaze
                              wrote on last edited by
                              #20

                              @SGaist i try to stimulate the crash again and i try to post it! thank you

                              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