DON'T USE QPointer! It is unofficially deprecated by Qt and the advice on the lists is to not use it. It has issues with const correctness and forward declared types which can result in slicing. GCC will warn you of this but Microsoft's compilers will NOT!
You're much better off using shared_ptr and weak_ptr which are standard in C++.
Memory management really isn't hard, even with bald pointers. Modern managed languages are often very slow because they can't be as smart as the programmer.
This is only the case if or because Test is a QObject, which automatically deletes its children, right? So if Test would not inherit QObject, there would still be a memory leak without calling delete on mChild, or am I wrong (as I am still in my "Learning Phase")?
@ffxme You might be accessing a pointer pointing to invalid data (i.e. you've freed the data the pointer points to, but continue using the pointer). I suggest you compile in debug mode and look at the stack trace when the crash/segfault happens. If you've roughly located the problem, set a break point and start stepping through the code.
I LOVE YOU!!!
post15951 2 weeks ago
thanks for tutorial
karthaxx 4 weeks ago
hi everyone. I want to program a antivirus, how can I do that?
aness07krami012 4 weeks ago in playlist C++ Qt Programming
I hope my phone won't come and hit me in the head with a all the crap I stored in it's memory...
Thank god restarting the phone cleares it...right?...
JohnsonGetDown 1 month ago in playlist C++ Qt Programming
@ffxme Sounds like a double delete. After manually deleting a pointer, be sure to set it to zero or NULL.
Danny77uk 1 month ago
DON'T USE QPointer! It is unofficially deprecated by Qt and the advice on the lists is to not use it. It has issues with const correctness and forward declared types which can result in slicing. GCC will warn you of this but Microsoft's compilers will NOT!
You're much better off using shared_ptr and weak_ptr which are standard in C++.
Memory management really isn't hard, even with bald pointers. Modern managed languages are often very slow because they can't be as smart as the programmer.
Danny77uk 1 month ago
~ 5:00
This is only the case if or because Test is a QObject, which automatically deletes its children, right? So if Test would not inherit QObject, there would still be a memory leak without calling delete on mChild, or am I wrong (as I am still in my "Learning Phase")?
Aericur 1 month ago
@ffxme Google cppcheck. A very good app for finding errors
olmiilmo 1 month ago
@DerCrossi The thing is, it only crashes 1% of the time, if I was pointing to a freed pointer you would think it would crash every time no?
ffxme 1 month ago
@ffxme You might be accessing a pointer pointing to invalid data (i.e. you've freed the data the pointer points to, but continue using the pointer). I suggest you compile in debug mode and look at the stack trace when the crash/segfault happens. If you've roughly located the problem, set a break point and start stepping through the code.
DerCrossi 1 month ago