title: QT program crashing when using the extern keyword
body: <p>I'm trying to use a global object for different classes using the extern keyword but this somehow doesn't work in QT.</p>
  <p>Basically I wanted to create a common GraphicsScene Object to draw rectangles in the same scene but in different classes. That's why I thought a global object &quot;scene_&quot; would be a good choice here.</p>
  <p><strong>manwindow.cpp</strong> :</p>
  <pre><code>QGraphicsScene *scene_ = new QGraphicsScene();
  
  MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent)
      , ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
      scene_-&gt;setSceneRect(-300,-300,600,600);
      ui-&gt;graphicsView-&gt;setScene(scene_);
  
      QGraphicsRectItem *rectItem = new QGraphicsRectItem();
      rectItem-&gt;setRect(0,0,200,200);
  
      scene_-&gt;addItem(rectItem);
  }
  
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  </code></pre>
  <p><em><strong>mainwindow.h</strong></em>:</p>
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  #include &lt;QGraphicsScene&gt;
  
  #include &lt;QMainWindow&gt;
  
  extern QGraphicsScene *scene_;
  
  QT_BEGIN_NAMESPACE
  namespace Ui { class MainWindow; }
  QT_END_NAMESPACE
  
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          MainWindow(QWidget *parent = nullptr);
          ~MainWindow();
      
      private:
          Ui::MainWindow *ui;
      };
      #endif // MAINWINDOW_H    
  </code></pre>
  <p>Here I wanted to retrieve the same object pointer _scene from mainwindow.h  and add a second rectangle to it.</p>
  <p><strong>A.c</strong> :</p>
  <pre><code>    #include &quot;a.h&quot;
      #include &quot;mainwindow.h&quot;
      #include &lt;QGraphicsRectItem&gt;
      
      A::A()
      {
          QGraphicsRectItem *rectItem2 = new QGraphicsRectItem();
          rectItem2-&gt;setRect(0,0,200,200);
          scene_-&gt;addItem(rectItem2);
      }
  </code></pre>
  <p><strong>main.cpp</strong> :</p>
  <pre><code>#include &quot;mainwindow.h&quot;
  
  #include &lt;QApplication&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
      return a.exec();
  }
  </code></pre>
  <p>The program crashes immediately when running it. (Due to the keyword implementation)</p>
  <pre><code>10:17:26: The program has unexpectedly finished.
  10:17:26: The process was ended forcefully.
  Desktop_Qt_6_2_1_MinGW_64_bit-Debug\debug\test.exe crashed.
  </code></pre>
  <p>How do I fix this issue or is there another way to implement this?</p>