I need to display a dynamic amount of QGraphicsRectItems in a QGraphicsView in rows and columns, so I decided to create a 2D array, but I always get an error. This is my header:

Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QGraphicsRectItem>
  5. #include <QMainWindow>
  6. #include <QGraphicsScene>
  7.  
  8. namespace Ui{
  9. class MainWindow;
  10. }
  11.  
  12. class MainWindow : public QMainWindow{
  13. Q_OBJECT
  14.  
  15. public:
  16. explicit MainWindow(QWidget *parent = 0);
  17. ~MainWindow();
  18.  
  19. private:
  20. Ui::MainWindow *ui;
  21. QGraphicsRectItem*** objRect; //This would be my 2D array
  22. };
  23.  
  24. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 


This is how I instance it:

Qt Code:
  1. objRect = new QGraphicsRectItem**[x];
  2. for(int i = 0; i < x; i++){
  3. objRect[i] = new QGraphicsRectItem*[x];
  4. }
To copy to clipboard, switch view to plain text mode 


The code above runs perfectly with no errors. But whenever I try to do something with it, like establishing the size of one of the rectangles, it throws me an error message:

Qt Code:
  1. objRect[0][0]->setRect(0,0,100,100);
To copy to clipboard, switch view to plain text mode 


If I run the program normally, no error message appears, but the window doesn't even appear. I can only see the error message if I run the project in Debug mode.

This is the error message:

2017-08-11.jpg

"The inferior stopped because it received a message from the operating system"

Signal name: SIGSEGV

Signal meaning: Segmentation fault

I've tried a lot of different ways of instancing it, but nothing seems to work.