title: Is storing pyQT widgets in a list bad form?
body: <p>So I am building I program that manages a bunch of custom slider widgets. Currently, I have a slider_container(class) that holds a list of slider objects(class). These slider objects are then inserted into the layout in the main window. This has been working well while I was only adding and moving the position of the sliders up and down. But when I try to delete the sliders, everything goes bad. When ever there the list of slider is manipulated (add, move or delete a slider), the clear and rebuild functions are called in the main window as seen below.</p>
  
  <pre><code>def clear_layout(self, layout):
      print "Cleared Layout..."
      while layout.count() &gt; 0:
          item = layout.takeAt(0)
          widget = item.widget()
          if widget is not None:
              widget.deleteLater()
  
  def rebuild_slider_display(self):
      """ Delete the old sliders, then add all the new sliders """
      self.clear_layout(self.slider_layout)
  
  
      print "Rebuild layout..."
      print len(self._widgets.widgets)
      for i, widget in enumerate(self._widgets.widgets):
          print widget.slider_name, " ", i
          self.slider_layout.insertWidget(i, widget)
      print "Layout widget count: ", self.slider_layout.count()
  </code></pre>
  
  <p>Currently I am running into this error on this line "self.slider_layout.insertWidget(i, widget)"</p>
  
  <pre><code>    RuntimeError: wrapped C/C++ object of type SliderWidget has been deleted 
  </code></pre>
  
  <p>My hunch is that storing the actual widget in the widget container is bad form. I think what is happening when I deleteLater() a widget, is that it isnt just deleting a widget from the list, it actually deletes the widget class that was store in the widget container itself.</p>
  
  <p>Hopefully that is explained clearly, thanks for your help in advance.</p>
  
  <p>Edit:</p>
  
  <p>Here is the widget class:</p>
  
  <pre><code>class SliderWidget(QWidget, ui_slider_widget.Ui_SliderWidget):
  """ Create a new slider. """
  def __init__(self, name, slider_type, digits, minimum, maximum, value, index, parent=None):
      super(SliderWidget, self).__init__(parent)
      self.setupUi(self)
  
      self.slider_name = QString(name)
      self.expression = None
      self.accuracy_type = int(slider_type)
      self.accuracy_digits = int(digits)
      self.domain_min = minimum
      self.domain_max = maximum
      self.domain_range = abs(maximum - minimum)
      self.numeric_value = value
      self.index = index
  
      #self.name.setObjectName(_fromUtf8(slider.name))
      self.update_slider_values()
  
      self.h_slider.valueChanged.connect(lambda: self.update_spinbox())
      self.spinbox.valueChanged.connect(lambda: self.update_hslider())
      self.edit.clicked.connect(lambda: self.edit_slider())
  
  # A unique has for the slider.    
  def __hash__(self):
      return super(Slider, self).__hash__()
  
  # How to compare if this slider is less than another slider.    
  def __lt__(self, other):
      r = QString.localAware.Compare(self.name.toLower(), other.name.toLower())
      return True if r &lt; 0 else False
  
  # How to compare if one slider is equal to another slider.    
  def __eq__(self, other):
      return 0 == QString.localAwareCompare(self.name.toLower(), other.name.toLower())
  </code></pre>
  
  <p>And here is the actually creation of the widget in the widget container:</p>
  
  <pre><code>def add_slider(self, params=None):
      if params:
          new_widget = SliderWidget(params['name'], params['slider_type'], params['digits'], params['minimum'], 
                                      params['maximum'], params['value'], params['index'])
      else:
          new_widget = SliderWidget('Slider_'+str(self.count()+1), 1, 0, 0, 50, 0, self.count())
  
      #new_widget.h_slider.valueChanged.connect(self.auto_save)
      #new_widget.h_slider.sliderReleased.connect(self.slider_released_save)
      new_widget.move_up.clicked.connect(lambda: self.move_widget_up(new_widget.index))
      new_widget.move_down.clicked.connect(lambda:     self.move_widget_down(new_widget.index))
      self.widgets.append(new_widget)
  </code></pre>
  
  <p>Thanks for all the help!</p>