I am trying to develop a project using qt but I have faced two problems both for adding items to a scene! I have a class containing my background object and it gets a pointer to my scene in its constructor.
I tried "scene->addItem(this)" to add the background to the scene. however, while running the project, it is reported that the item has already been added to the scene! here is the only place I invoke addItem.
I am also trying to make new objects of a few classes and put them inside a QList. While adding them, the items do not appear on the scene at all!
Here is the class:
class Test : public QObject, public QGraphicsPixmapItem{
Q_OBJECT
public:
Test(QGraphicsScene *s){
scene = s;
setPixmap(QPixmap("a.jpg"));
setPos(0, 0);
scene->addItem(this);
}
void mousePressEvent(QGraphicsSceneMouseEvent *event){
list.push_back(new A(QPixmap("b.png")));
scene->addItem(list.back());
}
private:
QGraphicsScene *scene;
}
P.S. A is class inheriting B which itself, inherits public QObject and public QGraphicsPixmapItem. The list also contains a couple of objects from type(B *).