Hi! I'm having a relevant doubt so I would like someone to clarify it if possible. I am in this situation: I created a structure which should be assignable, so that I can put it into a container. In this specific case I'm interested in QHash. This is an example:
struct MyStruct
{
}
struct MyStruct
{
QString aString;
QString anotherString;
QImage anImage;
}
To copy to clipboard, switch view to plain text mode
as far as I can understand this should be assignable already without default contructor, copy constructor or operator= override.
First question is: if I copy two MyStruct's this way:
MyStruct s;
MyStruct p = s;
MyStruct s;
MyStruct p = s;
To copy to clipboard, switch view to plain text mode
Do I use implicit sharing on the two strings and the image? I mean, does the default operator= of the C++ uses operator= on each of the members? So, when one of those is destroyed, the other one remains valid?
But what happens when I insert MyStruct in a QHash? If I define a QHash like QHash<int, MyStruct>, and I insert MyStruct's inside, do I have that all the members are only shallow copied with copy-on-write?
And what happens if I clear the QHash? Do I get that all the values (and keys in case) are destroyed (and member's refcount is decreased)?
And If I placed a pointer to MyStruct (the object is in the heap then)? I read that in that case the memory is not freed and I have to use qDeleteAll, is this correct?
Thanks for any clarification!
Bookmarks