PDA

View Full Version : Issue with List of objects made of QObject



alizadeh91
3rd June 2013, 15:09
Hi,
I have list of objects(made of QObject – myList<myObject>).
For some reasons user may be want to modify this list or maybe he/she want to cancel the modifications.
The solution which has came into my mind is to make a copy of my list and give it to user while keeping original one.
so whenever user modify copied list, i have original list so i can change it or revert it based on what user wants.
But the problem is that the objects are made of QObject, so they can not be copied(Copy constructor and
assignment have disabled in qobject)!!! I don’t know what else to do?!
If i define myObject as pointers then i can’t copy the list because they have defined as pointer
Thanks if someone can help me through this. or may be i can use another approach?

Santosh Reddy
3rd June 2013, 16:20
First thing you have to use QList if pointer to QObject. i.e. QList<QObject *> or simply use QObjectList.


If i define myObject as pointers then i can’t copy the list because they have defined as pointer
Why you not able to copy the list? You can copy the QObjectList even though it has pointers.

alizadeh91
3rd June 2013, 17:09
becuase if i copy it, it will copy the pointers not the values. isn't it right?

pkj
3rd June 2013, 17:19
No, you cannot go there. The best you can do is to externalize your QObject class internals into another class. A memento design pattern like object and pass those around in the list. Since QObject cannot be copied, there is no other way.

wysota
3rd June 2013, 20:38
becuase if i copy it, it will copy the pointers not the values. isn't it right?

Yes, it is correct. And what's wrong with that?