Yes, my solution is somewhat particular.
This does not mean that there isn't a general one.
Unfortunately I am at work now, but I'll be happy to help once I'm done here.
Regards
Yes, my solution is somewhat particular.
This does not mean that there isn't a general one.
Unfortunately I am at work now, but I'll be happy to help once I'm done here.
Regards
Hi,
here's a suggestion:
In this case you are not iterating and deleting the children list(dangerous!), but you are implicitely working on a copy.Qt Code:
void Molecule::deleteSelected() { if( isSelected ){ deleteLater(); return; } foreach( Bond *bond, findChildren<Bond*>() ) bond->deleteSelected(); }To copy to clipboard, switch view to plain text mode
Also you can remove the setName() calls, since you are only using the class names. You can get to them by calling QMetaObject::className()
Consider this scenario...
Suppose there are 5 bonds( bond1, .... bond5), from the foreach statement,
Now
1) First Iteration leads to deletion of bond1 and bond3;
2) Second iteration works fine.
3) Third iteration, OH!!!Crashes, the bond is already deleted in
iteration1.
Fails...
Please provide some solution where the list gets updated
automatically like how it worked in Qt3.
Please run the same code without any changes in Qt3 (provided in first post) and then
run again the same code after porting to Qt4, you
can find the differences..
Please help
Bookmarks