PDA

View Full Version : subclasing a Qlist?



Ricardo_arg
21st March 2010, 07:19
i have problems when i try to use the iterator with a list an a custom class T. it seems that is out of scope.
this is an example that explains better my point.

include "t.h"
include <QList>
class p
{
public:
void my_function();
private:
QList<T> list;
}
in the implementation:

T::my_funcion()
{
QList<T>::iterator it;//here it seems to be the problem,, because i think this class P, isnt the main class
for(it=list.begin();it!=list.end();it++)
{
//at this time i an only avaible to do this
list.at(i).show();//where show() is an public function of the object T
}
//obviouslly the compiler show the message warning that is not right to do this
//thenn compiler doesnt do nothinhg and do not compile the program
}
the main intention is to declare a object that use the QList class an declare function to work whit this class in the main class
some help pleasa!!

aamer4yu
21st March 2010, 07:38
Is your T derived from QWIdget ?
If yes, you are doing it wrong. From the code, you are storing list as QList<T>. This requires copy constructor of T.
But QWidget doesnt provide that.
So your implementation should be like QList<T*>, and then call list.at(i)->show();

Lykurg
21st March 2010, 08:00
Why are you mixing iterators and index basex access. The scope you posted is nonsens. Try to skip the iterator based aproach and try to use only the indexed based one:
for (int i = 0; i < list.size(); ++i) {/*...*/}

Ricardo_arg
21st March 2010, 08:40
gracias, its was derived from Qwidget