Whats wrong with QList<QGraphicsItem>
Under gcc:
Code:
#include <QtGui>
#include <QtCore>
class test
{
public:
test()
: list( QList<QGraphicsLineItem>() )
{ }
private:
QList<QGraphicsLineItem> list;
};
int main(int argc, char *argv[])
{
test t;
return app.exec();
}
returns:
Code:
In file included from ..\Qt\include/QtCore/qlist.h:1,
from ..\Qt\include/QtCore/../../src/corelib/kernel/qobject.h:50,
from ..\Qt\include/QtCore/qobject.h:1,
from ..\Qt\include/QtCore/../../src/corelib/io/qiodevice.h:46,
from ..\Qt\include/QtCore/qiodevice.h:1,
from ..\Qt\include/QtCore/../../src/corelib/xml/qxmlstream.h:45,
from ..\Qt\include/QtCore/qxmlstream.h:1,
from ..\Qt\include/QtCore/QtCore:3,
from ..\Qt\include\QtGui/QtGui:3,
from main.cpp:1:
..\Qt\include/QtGui/../../src/gui/graphicsview/qgraphicsitem.h: In member function 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = QGraphicsLineItem]':
..\Qt\include/QtCore/../../src/corelib/tools/qlist.h:606: instantiated from 'void QList<T>::detach_helper() [with T = QGraphicsLineItem]'
..\Qt\include/QtCore/../../src/corelib/tools/qlist.h:114: instantiated from 'QList<T>::QList(const QList<T>&) [with T = QGraphicsLineItem]'
main.cpp:8: instantiated from here
..\Qt\include/QtGui/../../src/gui/graphicsview/qgraphicsitem.h:865: error: 'QGraphicsLineItem::QGraphicsLineItem(const QGraphicsLineItem&)' is private
..\Qt\include/QtCore/../../src/corelib/tools/qlist.h:370: error: within this context
..\Qt\include/QtGui/../../src/gui/graphicsview/qgraphicsitem.h:865: error: 'QGraphicsLineItem::QGraphicsLineItem(const QGraphicsLineItem&)' is private
..\Qt\include/QtCore/../../src/corelib/tools/qlist.h:383: error: within this context
Doing the same thing, but replacing QGraphicsLineItem with int or anything else works... I'm at a loss
Re: Whats wrong with QList<QGraphicsItem>
Have you tried a list of references or pointers rather than a list of values?
Re: Whats wrong with QList<QGraphicsItem>
QList<QGraphicsItem &>
fails because you can't new a reference
QList<QGraphicsItem *>
works, but I'm starting to think I should go about this differently.
Here's the thing:
I'm trying to make a QPlotAxis inherits QPlotItem inherits QGraphicsItem. The Axis containts the arrow (axis itself) and the labels (lines and text). I thought, well make a QList<QGraphicsLineItem> for the arrow, one for the markings (adaptive of window size) and a QList<QGraphicsTextItem> for the labels and axis name and work with that, but I guess it won't let me. What are the repercussions of working with a pointer list vs a normal one?
Or I could do it this way: create QPainterPath that does it all?
Thanks
Re: Whats wrong with QList<QGraphicsItem>
QList<SomeClass> requiers SomeClass to have assignment operator (=) to make a copy of it.
Since QGraphicsItem doesnt seem to have it, you cannot use it directly in QList<QGraphicsItem> .
QList<QGraphicsItem*> is good, theres no problem with it.
Re: Whats wrong with QList<QGraphicsItem>
Your answer made me search the docs because I couldn't remember having read something like that, while your explanation does make sense...
Finally, I found a very interesting section:
http://qt.nokia.com/doc/4.6/containe...tainer-classes
Just posting for future reference...
Re: Whats wrong with QList<QGraphicsItem>
Ah, great link!
Quote:
If you attempt to instantiate a QList<QWidget>, the compiler will complain that QWidget's copy constructor and assignment operators are disabled. If you want to store these kinds of objects in a container, store them as pointers, for example as QList<QWidget *>.
That says it all :)
Thanks, should have read the docs better, again...
Re: Whats wrong with QList<QGraphicsItem>
The QGraphicsItem is a abstrac class and can't be used directly, QGraphicsItem::paint ()is a pure virtual function, so you can't create a object of this class. QGraphics is used as a base class
because of this..
Code:
QList<QGraphicsItem> //don't compile. can't create a object of a abstract class
QList<QGraphicsItem *> // works because is posible create a pointer of a abstract class, polymorphism
QList<SubclassGraphicsItem> //works because the class is not abstract