Qt program crashes after some minutes run time!
-
Hi, I have a program but after some time crashes and i cannot find what is wrong at my code, the debugger jumps to qstring.h and shows the below line:
inline QString::~QString() { if (!d->ref.deref()) free(d); }
Can someone tell me what can i do to find out the problem ?
-
First thing to do is look at the stack trace and see if some of your code is there.
-
Hi,
To add to @Chris-Kawa , and since it happens after a moment, check for a memory leak in your code.
-
It's really hard to help you with a one-liner. There are number of problems that can cause this. Lon, whatever that is, may be invalid, a, whatever that is, may be invalid. Either of setNum or lon can have corrupting side-effects. There can be unrelated memory corruption that happens to manifest here. Without more details it's a pure guesswork on our side.
-
You have right, the code it's enormous to be posted in a thread.
It is also difficult to me , to find what is going wrong! But i try to post something more helpful! -
If it's that big, try running a tool like cppcheck to see if you missed something
-
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 ?