title: segfault while finding sames in Same Game using QT-C++
body: <p>I'm trying to learn QT and while learning I wanted to develop a Same Game.
  I have a subclass of QGraphicsItem which is Gem
  and a subclass of QGraphicsScene whics is GameScene.</p>
  
  <p>I connected clickedOnMe signal of each Gem in the scene to the clicked slot of GameScene.
  Signal provides a pointer to the clicked object. And GameScene class holds a list of pointers to the Gem's in it.</p>
  
  <p>So far i have tried only finding end deleting the sames, no replacement of any gem. When I run the game and click on a gem it sometimes works well and deletes all same gems and sometimes it gives segmentation fault. I couldn't understand where my problem is.</p>
  
  <pre><code>void GameScreen::clicked(Gem *cGem){
  
  // cGem is the clicked gem
  
  if(cGem)
  {
   //find cGem in the list and erase from list
      QList&lt;Gem*&gt;::Iterator i = gems-&gt;begin();
      for(; i != gems-&gt;end(); ++i)
      {
          if(*(*i) == *cGem)
          {
              gems-&gt;erase(i);
              break;
          }
      }
      // end of erasing
  QList&lt;Gem*&gt; neighbours;
      for(i=gems-&gt;begin(); i != gems-&gt;end(); ++i)
      {
          if((*i) &amp;&amp; (*i)-&gt;doesItTouch(cGem) &amp;&amp; (*i)-&gt;getColor() == cGem-&gt;getColor())
              neighbours.append(*i);
      }
  
      delete cGem;
  
      while(!neighbours.isEmpty())
      {
          clicked(neighbours.first());
          neighbours.removeFirst();
      }
  
  }
  
  return;
  </code></pre>
  
  <p>}</p>
  
  <p>and here is the Gem::doesItTouch(Gem *oGem)</p>
  
  <pre><code>if(oGem)
      return (qAbs(x - oGem-&gt;getX()) + qAbs(y - oGem-&gt;getY())) &lt;= 1;
  return false;
  </code></pre>