title: Having trouble debugging segfault, connect() involved
body: <p>Hi :) i'm currently trying to create a character sheet generator for a home-made RPG :) I'm having some troubles with debugging a strange segfault.</p>
  
  <p>What happen exactly :</p>
  
  <ol>
  <li>I initialize the _skills in my _c CCharacter object, then call a first time updateSkillBoxes(). It works perfectly.</li>
  <li>I can add other CUSkill in my _skills, call again updateSkillBoxes(), they are added without trouble</li>
  <li>If i change the name of one skill using the QComboBox name, it calls onSkillChanged(), end the function without crashing (i see the "onSkillChanged() finished" qDebug() message), and then crashes in app.exec() in my main.cpp </li>
  </ol>
  
  <p>What i have tried :</p>
  
  <ol>
  <li>Directly call to updateSkillBoxes() on my connect (slighty changed the code to update the data inside) : same issue.</li>
  <li>put the connect in the initialisation of CSkillInput, or in onSkillChanged, same error</li>
  <li>remove the connect in updateSkillBoxes(), and connect onSkillChanged() to a button in the UI. It worked perfectly, so the function seems to works (except the connect part)</li>
  </ol>
  
  <p>Here is the code :</p>
  
  <pre><code>void CGenerator::updateSkillBoxes()
  {
      qDebug() &lt;&lt; "updateSkillBoxes() started";
      //First we remove
      int skillNum=_skillI.size();
      for(int i=0;i&lt;skillNum;i++)
      {
          delete(_skillI.takeAt(0));
          delete(_skillInputLayout.takeAt(0));
          delete(_skillInputBox.takeAt(0));
      }
  
      //Clean skillGrid
      QLayoutItem *child;
      while ((child = _skillGrid-&gt;takeAt(0)) != 0)
      {
          delete child-&gt;widget();
          delete child;
      }
      delete _skillGrid;
  
      _skillGrid = new QGridLayout;
      for(int i=0;i&lt;_c-&gt;getSkill().size();i++)
      {
          CUSkill *skill = _c-&gt;getSkill()[i];
          QPointer&lt;QGridLayout&gt; tmpLayout = new QGridLayout;
          QPointer&lt;QGroupBox&gt; tmpBox = new QGroupBox;
          //Recreate new input
          QPointer&lt;CSkillInput&gt; tmpInput = new CSkillInput(d-&gt;getSkillNameList(), d-&gt;getSkillIdList());
          tmpInput-&gt;createPerkInput(d-&gt;getUsablePerk(skill-&gt;getParam("id"), skill-&gt;getParam("level").toInt()),
                                    _c-&gt;getPerkNumberForSkill(i));
          tmpInput-&gt;updateInput(skill);
          _skillI.append(tmpInput);
          //Add everything to the gridlayout
          tmpLayout-&gt;addWidget(new QLabel("Nom"), 0, 0);
          tmpLayout-&gt;addWidget(new QLabel("Niveau"), 0, 1);
          tmpLayout-&gt;addWidget(new QLabel("Spécial"), 0, 2);
          tmpLayout-&gt;addWidget(new QLabel("Vitesse"), 0, 3);
          tmpLayout-&gt;addWidget(new QLabel("Type"), 0, 4);
          tmpLayout-&gt;addWidget(_skillI[i]-&gt;level, 1, 1);
          tmpLayout-&gt;addWidget(_skillI[i]-&gt;special, 1, 2);
          tmpLayout-&gt;addWidget(_skillI[i]-&gt;speed, 1, 3);
          tmpLayout-&gt;addWidget(_skillI[i]-&gt;type, 1, 4);
          tmpLayout-&gt;addWidget(_skillI[i]-&gt;name,1, 0);
          //Now we add the perks (they have been filled with createPerkInput() earlier
          for(int j=0;j&lt;_skillI[i]-&gt;perkList.size();j++)
          {
              tmpLayout-&gt;addWidget(_skillI[i]-&gt;perkList[j], 2+j, 0);
              tmpLayout-&gt;addWidget(_skillI[i]-&gt;perkLevel[j], 2+j, 1);
              tmpLayout-&gt;addWidget(_skillI[i]-&gt;perkDesc[j], 2+j, 2, 1, -1);
          }
          //I'm not actually sure i need to access those later, but just to be sure i'll put them somewhere
          _skillInputLayout.append(tmpLayout);
          _skillInputBox.append(tmpBox);
          _skillInputBox[i]-&gt;setLayout(_skillInputLayout[i]);
          if(i%2 == 0)//We want to put 2 skills by line (cuz it's fancier), so ... different case
          {
              _skillGrid-&gt;addWidget(_skillInputBox[i], i/2, 0, 1, 1, Qt::AlignTop);
          }
          else
          {
              _skillGrid-&gt;addWidget(_skillInputBox[i], (i-1)/2, 1, 1 , 1, Qt::AlignTop);
          }
          connect(_skillI[i]-&gt;name, SIGNAL(currentIndexChanged(int)), this, SLOT(onSkillChanged()));
      }
      _skillBox-&gt;setLayout(_skillGrid);
      qDebug() &lt;&lt; "updateSkillBoxes() finished";
  }
  
  void CGenerator::onSkillChanged()
  {
      qDebug() &lt;&lt; "onSkillChanged() started";
      //We need to find which skill has been updated !
      for(int i=0;i&lt;_skillI.size();i++)
      {
          QString newId = _skillI[i]-&gt;name-&gt;itemData(_skillI[i]-&gt;name-&gt;currentIndex()).toString();
          if(newId != _c-&gt;getSkill()[i]-&gt;getParam("id"))
          {
              _c-&gt;updateSkill(i, newId);
              CSkillInput *input;
              input = _skillI[i];
              _c-&gt;setSkillParam(i, "level", QString::number(input-&gt;level-&gt;value()));
              _c-&gt;setSkillParam(i, "special",  input-&gt;special-&gt;itemData(input-&gt;special-&gt;currentIndex()).toString());
              _c-&gt;updatePerkNumber(i, _c-&gt;getPerkNumberForSkill(i));
              updateSkillBoxes();
          }
      }
      qDebug() &lt;&lt; "onSkillChanged() finished";
  }
  </code></pre>
  
  <p>And the CSkillInput code :</p>
  
  <pre><code>CSkillInput::CSkillInput(QStringList skillName, QStringList skillId)
  {
      name = new QComboBox;
      for(int i=0;i&lt;skillName.size();i++)
      {
          name-&gt;addItem(skillName[i], skillId[i]);
      }
      speed = new QComboBox;
      speed-&gt;addItem("Rapide","f");
      speed-&gt;addItem("Moyen", "m");
      speed-&gt;addItem("Lent", "s");
      speed-&gt;setEnabled(false);
      type = new QComboBox;
      type-&gt;addItem("Martial", "w");
      type-&gt;addItem("Magique", "m");
      type-&gt;addItem("Divers", "d");
      type-&gt;setEnabled(false);
      special = new QComboBox;
      special-&gt;addItem("Rien", "n");
      special-&gt;addItem("Talent", "t");
      special-&gt;addItem("Don", "g");
      level = new QSpinBox;
      level-&gt;setMaximum(10);
  }
  
  CSkillInput::~CSkillInput()
  {
      this-&gt;name-&gt;disconnect();
  }
  
  void CSkillInput::createPerkInput(QList&lt;CPerk *&gt; perks, qint32 perkNumber)
  {
      //First we need to make a list of the perks name
      for(int i=0;i&lt;perkNumber;i++)
      {
          //Kinda ugly but it's because we need to generate differents object
          QComboBox *tmpList = new QComboBox;
          for(int i=0;i&lt;perks.size();i++)
          {
              tmpList-&gt;addItem(perks[i]-&gt;getParamStr("name"), perks[i]-&gt;getParamStr("id"));
          }
          QSpinBox *tmpLevel = new QSpinBox;
          QLineEdit *tmpDesc = new QLineEdit;
          tmpLevel-&gt;setValue(perks[0]-&gt;getParamInt("level"));
          tmpLevel-&gt;setReadOnly(true);
          tmpDesc-&gt;setText(perks[0]-&gt;getParamStr("desc"));
          tmpDesc-&gt;setToolTip(perks[0]-&gt;getParamStr("desc"));
          perkList &lt;&lt; tmpList;
          perkLevel &lt;&lt; tmpLevel;
          perkDesc &lt;&lt; tmpDesc;
      }
  }
  
  void CSkillInput::updateInput(CUSkill *skill)
  {
      if(skill-&gt;getParam("id") != name-&gt;itemData(name-&gt;currentIndex()))
      {
          name-&gt;setCurrentIndex(name-&gt;findData(skill-&gt;getParam("id")));
      }
      level-&gt;setValue(skill-&gt;getParam("level").toInt());
      speed-&gt;setCurrentIndex(speed-&gt;findData(skill-&gt;getParam("speed")));
      special-&gt;setCurrentIndex(special-&gt;findData(skill-&gt;getParam("special")));
      type-&gt;setCurrentIndex(type-&gt;findData(skill-&gt;getParam("type")));
  }
  </code></pre>
  
  <p>And the header (removed some irrelevant things in CGenerator for clarity)</p>
  
  <pre><code>class CSkillInput : public QObject
  {
      Q_OBJECT
  public:
      CSkillInput(QStringList skillName, QStringList skillId);
      ~CSkillInput();
  
      void createPerkInput(QList&lt;CPerk *&gt; perks, qint32 perkNumber);
      void updateInput(CUSkill *skill);
  
      QPointer&lt;QComboBox&gt; name;
      QPointer&lt;QComboBox&gt; speed;
      QPointer&lt;QComboBox&gt; type;
      QPointer&lt;QComboBox&gt; special;
      QPointer&lt;QSpinBox&gt; level;
      QList&lt;QPointer&lt;QComboBox &gt; &gt; perkList;
      QList&lt;QPointer&lt;QSpinBox &gt; &gt; perkLevel;
      QList&lt;QPointer&lt;QLineEdit &gt; &gt; perkDesc;
  };
  
  class CGenerator : public QWidget
  {
      Q_OBJECT
  public:
      CGenerator(CData *data);
      CData *d;
  
  private:
      CCharacter *_c;
      QGridLayout *_skillGrid;
      QGroupBox *_skillBox;
      QList&lt;QPointer&lt;QGridLayout&gt; &gt; _skillInputLayout;
      QList&lt;QPointer&lt;QGroupBox&gt; &gt; _skillInputBox;
      QList&lt;QPointer&lt;CSkillInput&gt; &gt; _skillI;
  private slots:
      void onSkillChanged();
      void updateSkillBoxes();
  };
  </code></pre>
  
  <p>Quick diagram to explain my UI : <a href="http://i.stack.imgur.com/SDHE2.png" rel="nofollow">http://i.stack.imgur.com/SDHE2.png</a></p>
  
  <p>And finally, my gdb stack on segfault :</p>
  
  <pre><code>(gdb) bt
  #0  QComboBoxPrivate::itemText (this=this@entry=0xbf2540, index=...) at widgets/qcombobox.cpp:1287
  #1  0x00007ffff769e58f in QComboBoxPrivate::_q_emitCurrentIndexChanged (this=this@entry=0xbf2540, index=...)
      at widgets/qcombobox.cpp:1279
  #2  0x00007ffff769e8eb in QComboBoxPrivate::setCurrentIndex (this=this@entry=0xbf2540, mi=...) at widgets/qcombobox.cpp:2049
  #3  0x00007ffff769eb4f in QComboBox::setCurrentIndex (this=this@entry=0xca4450, index=index@entry=2) at widgets/qcombobox.cpp:2025
  #4  0x00007ffff76a2f06 in QComboBox::wheelEvent (this=0xca4450, e=0x7fffffffd7e0) at widgets/qcombobox.cpp:3096
  #5  0x00007ffff7306748 in QWidget::event (this=0xca4450, event=0x7fffffffd7e0) at kernel/qwidget.cpp:8775
  #6  0x00007ffff72b348c in QApplicationPrivate::notify_helper (this=this@entry=0x659590, receiver=receiver@entry=0xca4450, 
      e=e@entry=0x7fffffffd7e0) at kernel/qapplication.cpp:4570
  #7  0x00007ffff72bb4fb in QApplication::notify (this=&lt;optimized out&gt;, receiver=0xca4450, e=0x7fffffffd7e0)
      at kernel/qapplication.cpp:4168
  #8  0x00007ffff6d8371d in QCoreApplication::notifyInternal (this=0x7fffffffe130, receiver=0xca4450, event=0x7fffffffd7e0)
      at kernel/qcoreapplication.cpp:955
  #9  0x00007ffff732cb49 in sendSpontaneousEvent (event=&lt;optimized out&gt;, receiver=&lt;optimized out&gt;)
      at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:234
  #10 QETWidget::translateWheelEvent (this=0x7fffffffd7e0, global_x=12526912, global_y=12486272, delta=12750704, buttons=..., 
      modifiers=..., orient=Qt::Vertical) at kernel/qapplication_x11.cpp:4578
  #11 0x00007ffff73309c8 in QETWidget::translateMouseEvent (this=this@entry=0x7fffffffe0b0, event=event@entry=0x7fffffffdc70)
      at kernel/qapplication_x11.cpp:4355
  #12 0x00007ffff732ee2c in QApplication::x11ProcessEvent (this=0x7fffffffe130, event=event@entry=0x7fffffffdc70)
      at kernel/qapplication_x11.cpp:3663
  #13 0x00007ffff7357ed2 in x11EventSourceDispatch (s=0x65c320, callback=0x0, user_data=0x0) at kernel/qguieventdispatcher_glib.cpp:146
  #14 0x00007ffff56f8c5d in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  #15 0x00007ffff56f8f48 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  #16 0x00007ffff56f8ffc in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  #17 0x00007ffff6db2d1d in QEventDispatcherGlib::processEvents (this=0x65add0, flags=...) at kernel/qeventdispatcher_glib.cpp:425
  #18 0x00007ffff7357f96 in QGuiEventDispatcherGlib::processEvents (this=&lt;optimized out&gt;, flags=...)
      at kernel/qguieventdispatcher_glib.cpp:204
  #19 0x00007ffff6d82271 in QEventLoop::processEvents (this=this@entry=0x7fffffffe050, flags=...) at kernel/qeventloop.cpp:149
  ---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---
  #20 0x00007ffff6d825d5 in QEventLoop::exec (this=this@entry=0x7fffffffe050, flags=...) at kernel/qeventloop.cpp:204
  #21 0x00007ffff6d88059 in QCoreApplication::exec () at kernel/qcoreapplication.cpp:1227
  #22 0x0000000000408ad5 in main (argc=1, argv=0x7fffffffe238) at ../../../../code/kustom/kustom-sheet-creator/main.cpp:34
  </code></pre>