title: Delete QGraphics Items from QGraphicsLinearLayout on QGraphicsScene
body: <p>I'm having a really frustrating problem, trying to delete qgraphicsitems in my application. I have a menu controller which is responsible for adding buttons to a layout and adding them to the scene. These buttons are all connected with custom signals and slots. When I change states, I want to delete this controller and remove all of these qgraphicsitems.</p>
  
  <p>Heres how I add them in my menu_controller.cpp:</p>
  
  <pre><code>QGraphicsWidget * temp;//this is used during iteration to add to the layout
  
      this-&gt;layout = new QGraphicsLinearLayout(Qt::Vertical);//q graphics view layout
      this-&gt;menu = new QGraphicsWidget;//holds the layout
  
  
      // initialize the proper buttons
      (this-&gt;game_state-&gt;is_logged_in()) ? (this-&gt;logged_in()) : (this-&gt;not_logged_in());//test whether or not the user is logged in to generate the correct menu
  
      // now iterate through each button and add to the layout
      for (int i = 0, z = this-&gt;buttons.size(); i &lt; z; i++) {
  
          temp = this-&gt;scene-&gt;addWidget(this-&gt;buttons[i]);//add widget to the scene
          this-&gt;layout-&gt;addItem(temp);//add this widget to the layou
          connect(this-&gt;buttons[i], SIGNAL(menu_selection(QString)), this, SLOT(set_menu_option(QString)));//connect the button to this
      }
  
      // set menu layout as the layout and then add the menu to the scene
      this-&gt;menu-&gt;setLayout(this-&gt;layout);
      this-&gt;position();
      this-&gt;scene-&gt;addItem(this-&gt;menu);
  </code></pre>
  
  <p>Finally, my destructor looks like this:</p>
  
  <pre><code>QGraphicsScene * scene = this-&gt;game_state-&gt;get_scene();
  
      QList&lt;QGraphicsItem *&gt; list = scene-&gt;items();
      QList&lt;QGraphicsItem *&gt;::Iterator it = list.begin();
  
      for (; it != list.end(); ++it)
          if (*it)
              scene-&gt;removeItem(*it);
  
      for (int i = 0, z = this-&gt;buttons.size(); i &lt; z; i++)
          disconnect(this-&gt;buttons[i], 0, 0, 0);//button not connected to anything
  
      // for each deletes each place in memory
      for_each(this-&gt;buttons.begin(), this-&gt;buttons.end(), utilities::delete_ptr());
  
      delete this-&gt;layout;//delete the layout container
      delete this-&gt;menu;//delete the menu
  </code></pre>
  
  <p>I remove each of the buttons from the scene, disconnect the connected buttons and then try to call delete on them.</p>
  
  <p>I get a segmentation fault each time. The scene items remove fine, and the disconnects work properly, but for some reason when I delete the items, it throws a segmentation fault and crashes the program.</p>