That would not work since the calling function passes a const pointer:
QModelIndex AModel
::itemToIndex(const A
*x,
int column
) const{ const A *parent = x->parent();
int row = parent->indexOfChild(x);
...
QModelIndex AModel::itemToIndex(const A *x, int column) const{
const A *parent = x->parent();
int row = parent->indexOfChild(x);
...
To copy to clipboard, switch view to plain text mode
Of course I could get rid of all the const. But I don't want to do that.
But it does work if I use the QList like this.
#include <QList>
class A
{
public:
A(A* parent = 0){ _list = new QList<const A*>(); _parent = parent;}
~A(){ delete _list;}
int indexOfChild(const A* x) const { return _list->indexOf( x, 0); }
private:
int i;
A *_parent;
QList<const A*> *_list;
};
#include <QList>
class A
{
public:
A(A* parent = 0){ _list = new QList<const A*>(); _parent = parent;}
~A(){ delete _list;}
int indexOfChild(const A* x) const { return _list->indexOf( x, 0); }
private:
int i;
A *_parent;
QList<const A*> *_list;
};
To copy to clipboard, switch view to plain text mode
I still don't really understand the previous error.
QList's method is declared like this.
int QList::indexOf ( const T
& value,
int from
= 0 ) const
int QList::indexOf ( const T & value, int from = 0 ) const
To copy to clipboard, switch view to plain text mode
The method will not modify T, or how do I have to read the const T& here?
I guess I have to get my Bruce Eckel's out again.
Bookmarks