title: Qt C++ : removing next-to-last item from QListWidget makes program crash
body: <p>in this program, items (<code>markers</code>) are added to a QListWidget calles <code>ui-&gt;lwMarkers</code>. These items can also be removed again by pressing the "Remove button" which calls the following function</p>
  
  <pre><code>void Form::on_pbRemoveMarker_clicked()
  {
      if (ui-&gt;lwMarkers-&gt;currentRow() &lt; 0) return;
  
      delete ui-&gt;lwMarkers-&gt;takeItem(ui-&gt;lwMarkers-&gt;currentRow());
  }
  </code></pre>
  
  <p>Inside the function, the first line is to make sure an item (marker) is actually selected.
  The second line is (at least, I hope) to delete the selected item.</p>
  
  <p>Adding and removing: all goes well, unless when you want to remove next-to-last item. Then it crashes, unfortunately. I do not see why.</p>
  
  <p>Can anyone shed a light on this issue?</p>
  
  <p>If it can help: the full code is from the qt-google-maps project: <a href="https://code.google.com/p/qt-google-maps/" rel="nofollow">https://code.google.com/p/qt-google-maps/</a> . This project uses the Google Maps API v2, I altered the code to use v3.</p>
  
  <p>The question that I ask, is a particular behaviour of their code, and I simply don't see the reason of the crash. Any help?</p>
  
  <p>The crash always happens just before the <code>delete</code>, I believe it is because of the <code>takeItem</code> and the error I get is as follows:
      ASSERT failure in QList::operator[]: "index out of range", file ../../QtSDK/Desktop/Qt/473/gcc/include/QtCore/qlist.h, line 464</p>