Hi all,

I'm experiencing a very funny problem with the Graphics View Framework (Mac OS, Qt 4.3.2, G++ 4).

I've created a very simple class, called Obstacle, that inherits from QGraphicsItem:

Qt Code:
  1. #ifndef OBSTACLE_H
  2. #define OBSTACLE_H
  3.  
  4. #include <QGraphicsItem>
  5.  
  6. class Obstacle : public QObject, public QGraphicsItem {
  7.  
  8. Q_OBJECT
  9.  
  10. public:
  11.  
  12. // Constructor
  13. Obstacle(int width, int height, bool movable);
  14.  
  15. // Size
  16. int obstacle_width, obstacle_height;
  17.  
  18. // itemChange() function
  19. QVariant itemChange(GraphicsItemChange change, const QVariant & value);
  20.  
  21. // Shape
  22. QRectF boundingRect() const;
  23. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
  24.  
  25. // Tooltip
  26. QString str_obstacle_tooltip;
  27.  
  28. signals:
  29. void dragged();
  30.  
  31. };
  32.  
  33. #endif
To copy to clipboard, switch view to plain text mode 

Since I need to use a lot of objects belonging to this class, I've chosen to create a couple of dynamically allocated vectors, defined as:

Qt Code:
  1. Obstacle *obstacles_A[], *obstacles_B[];
To copy to clipboard, switch view to plain text mode 

Then, I create the various instances using the "new" command and I add all the object to my scene:

Qt Code:
  1. obstacles_A[0] = new Obstacle(130, 82, true);
  2. obstacles_A[1] = new Obstacle(130, 82, true);
  3. obstacles_A[2] = new Obstacle(95, 190, true);
  4. obstacles_A[3] = new Obstacle(55, 230, true);
  5. ...
  6. obstacles_A[12] = new Obstacle(49, 38, true);
  7.  
  8. graphScene_Scene->addItem(obstacles_A[0]);
  9. graphScene_Scene->addItem(obstacles_A[1]);
  10. graphScene_Scene->addItem(obstacles_A[2]);
  11. graphScene_Scene->addItem(obstacles_A[3]);
  12. ...
  13. graphScene_Scene->addItem(obstacles_A[12]);
  14.  
  15. obstacles_A[0]->setPos(180,44);
  16. obstacles_A[1]->setPos(180,150);
  17. obstacles_A[2]->setPos(408,38);
  18. obstacles_A[3]->setPos(643,17);
  19. ...
  20. obstacles_A[12]->setPos(275,564);
To copy to clipboard, switch view to plain text mode 

Everything works fine in this way. Except if I try to create another object (the number 13). In this case, my application compiles correctly but I get an error during the linking.

This is why I'm using also another vector (obstacles_B). Using this second vector, I'm able to create more than 13 obstacles, but the amazing thing is that, when I add to the scene the first objects belonging to the second vector, the first object belonging to the first vector disappears from the scene! If I try with a second obstacle_b object, the second obstacle_a disappears, and so on.

Even more strange, it seems that the objects of the second vector "inherits" some properties from the disappearing objects: if I select (since the obstacles are selectable) one of the obstacles_b, it appears to my application as if I'd selected an object of the obstacles_a class.

Anyone could please help me to clarify this behaviour?

Many thanks,
Fabio Ruini