PDA

View Full Version : problem with QList



dreamer
9th May 2008, 19:28
I have a list of QGraphicsScene*:

QList<QGraphicsScene*>scenes;

Each element of the list would be a pointer of type QGraphicsScene*....
So scenes[i] return a QgraphicsScene* element????
From the documentation:
"On non-const lists, operator[]() returns a reference to the item".....so in my case, it will return a QGraphicsScene** element??

I want to pass this list of scenes, to an other myclass object:


myclass::myclass(QList<QGraphicsScene*> s){}


...but the compiler gives me error if a write
myclass(scenes)........

wysota
9th May 2008, 20:03
So scenes[i] return a QgraphicsScene* element????
Yes.



"On non-const lists, operator[]() returns a reference to the item".....so in my case, it will return a QGraphicsScene** element??
A reference, not a pointer. So QGraphicsScene*&, to be precise. It can be used as l-value and not r-value. For the latter you'll be using the const version and getting a regular pointer.


...but the compiler gives me error if a write
myclass(scenes)........

What kind of error?

aamer4yu
12th May 2008, 14:08
Shouldn't
myclass(scenes)
be
myclass myObject(scenes) ???

Hope am right ;)