Hi
I am using Qlist of objects of type MyObj in an instance of class AClass
Should I store the as a list of pointers to MyObj
QList <MyObj*> mylist;
To copy to clipboard, switch view to plain text mode
The function to add items to my list is as follows
void AClass
::addToList(const QList <MyObj>
&items
) {
foreach(MyObj m, items)
{
MyObj mm = new MyObj(m);
mylist.append(mm);
}
}
void AClass::addToList(const QList <MyObj> &items)
{
foreach(MyObj m, items)
{
MyObj mm = new MyObj(m);
mylist.append(mm);
}
}
To copy to clipboard, switch view to plain text mode
OR a list of MyObj instances and i add to the list as follows
QList <MyObj> mylist;
To copy to clipboard, switch view to plain text mode
void AClass
::addToList(const QList <MyObj>
&items
) {
mylist.append(items);
}
void AClass::addToList(const QList <MyObj> &items)
{
mylist.append(items);
}
To copy to clipboard, switch view to plain text mode
Which of the two cases above is the best way?
I have a problem removing items from the list as the MyObj class does not have a comparison operator
For example, I have a function to remove items from the list
void AClass
::removeFromList(const QList <MyObj>
&items
) {
foreach(MyObj m, items)
{
/*
what do I put in here if I want to remove 'items' from mylist
*/
}
}
void AClass::removeFromList(const QList <MyObj> &items)
{
foreach(MyObj m, items)
{
/*
what do I put in here if I want to remove 'items' from mylist
*/
}
}
To copy to clipboard, switch view to plain text mode
Regards
Bookmarks