QVector assignment operator ?
-
Hey
I have anniying issue. If I run my app in debug mode everything works, but if I run in release mode I get a crash. As far as I can tell I'm creating all pointers/null/initialize stuff properly but I'm still having issues. So far debuging lead me to believe that the issues is in copy constructor when I do :
QVetor<class> x = src.x;
I think when this happens, the copied classes which every they are made do not copy properly and manage their pointers. Even tho I have all default/copy and assignment constructor implemented... I think. Not sure but debuging this is hard when I cant actually run a debug...
Can any1 hint me what functions would qt call when executing the above command?
TIA
-
Hi,
Why can't you run in debug mode ?
What is stored in x ? -
What if you print the content of
src.x
? -
Debug mode runs fine, but it does not crash. Release mode crashes. I narrowed it down to vector=vector assignments I think... unsure. Its all black magic without debug.
So true. I'm just throwing Address Sanitizer and Valgrind in the ring. These tools might help finding issues like yours.
Or try to compile your code with other compiler or on other platform. It might already crash in debug then.
Good luck!
-
Hey
Ok I managed to solve it. Gotta say as much as I love QVector...some times I just want to..........
mChildren.resize(rhs.mChildren.size()); for (int x = 0; x < rhs.mChildren.size(); ++x) { mChildren[x].loadFromBox(rhs.mChildren[x]); }
Ended up doing this to fix it... Im afraid of everything now !
-
So the class contained in that QVector can't be copied ?
-
No idea, I had implemented class(const class&src) as well as operator= and class(){}.
I though all I needed was default constructor, copy constr and assign operator but apprently I was missing something...or when I was doing vec=src.vec. I was just adding ref counter to data inside other class and not doing deep copy? No idea... I just know it took 7h to debug :- (
-
What does
loadFromBox
compared to your copy constructor and assignment operator ?