PDA

View Full Version : Fill QList<MyOwnClass>



cit
24th January 2015, 11:31
Hi,
i want to fill QList with my own Class, but I don't know, when i have to use the "*".




List<MyOwnClass> *myList = new List<MyOwnClass>;

MyOwnClass *oneItem = new MyOwnClass;
oneItem.P1 = "firstMember";

myList->append(oneItem);





My Error say's something like:

error: no matching function for call to 'QList<MyOwnClass>::append(MyOwnClass*&)'
myList->append(oneItem);


Can anybody help?

^
^

ChrisW67
24th January 2015, 12:06
Your QList is declared to contain instances of MyOwnClass and you are trying to append a pointer-to-MyOwnClass. These are not the same thing, hence the error.

Assuming your class can be copied:


QList<MyOwnClass> list;
MyOwnClass a;
list.append(a);