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")?
I have this GUI program I wrote for windows in QT which does very large calculations, sometimes, if it has done many consecutive calculations it will crash although everywhere I use malloc I later use free and for the rest of the time I use the vector class which frees itself. What do you think may be causing these crashed?
@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.
You can make your example more verbose by implement the destructor/constructor/copy constructor with debug messages.
It is also interresting to implement the copy constructor/destructor and try some exception handling.
gehaktbal86 2 days ago
I LOVE YOU!!!
post15951 3 weeks ago
thanks for tutorial
karthaxx 1 month ago
hi everyone. I want to program a antivirus, how can I do that?
aness07krami012 1 month 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
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
Hello,
It will be great if you can upload a video on Unit Testing using QTestLib.
soumitra3115 1 month ago
how do u publish a qt app
iphone4life4 1 month ago
You should make audio programming tutorials :D
Fantasma25 1 month ago
Hello,
I have this GUI program I wrote for windows in QT which does very large calculations, sometimes, if it has done many consecutive calculations it will crash although everywhere I use malloc I later use free and for the rest of the time I use the vector class which frees itself. What do you think may be causing these crashed?
ffxme 1 month ago in playlist C++ Qt Programming
@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
@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 Google cppcheck. A very good app for finding errors
olmiilmo 1 month ago
@ffxme Sounds like a double delete. After manually deleting a pointer, be sure to set it to zero or NULL.
Danny77uk 1 month ago
Very great tutos !!! thx a lot :)
AminosYTC 1 month ago in playlist C++ Qt Programming
Excelent video!
xboxnissan 1 month ago