Qt program crashes after some minutes run time!
-
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.
-
@SysTech i made also this, but seems to be a problem at
a.lon and a.lat.a is a structure
i call thisif(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.
-
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?).
-
@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
-
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?
-
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.
-
@Chris-Kawa thank you, now i run the program to see if its ok!
-
Hi again, the program runs stable until is going in backstage, if for example i open the Mozilla to surfing, then the program crashes!
-
Can your share the backtrace of your crash ?