title: Segfault taking element from QList
body: <p>I get a SEGFAULT at the first line in the if-block, takeFirst().</p>
  
  <pre><code>if (!sendQueue.isEmpty()) {
      QString nxtcmd = sendQueue.takeFirst();
      port-&gt;write(nxtcmd.toLatin1());
      port-&gt;flush();
  }
  </code></pre>
  
  <p>I have code pushing 96 command strings into the queue with</p>
  
  <pre><code>if (completionHandlerQueue.empty()) {
  …
  } else {
      sendQueue.append(cmd_str);
  }
  </code></pre>
  
  <p>The latter happens in my main GUI code. The first bit is called by a signal by QExtSerialPort (when data is there to be read).</p>
  
  <p>sendQueue is a member and declared as such:</p>
  
  <pre><code>class SB::ModuleCommunicator : public QObject
  {
   …
   private:
       …
       QStringList sendQueue;
  </code></pre>
  
  <p>Now I'm not using threads and I assumed the Qt Event Loop would make everything work smoothly, but the full backtrace does tell me that there are in fact 3 threads.
  According to documentation, Qt Containers are only thread-safe for read only access.
  But the Queue is already full with all 96 strings when it crashes. So I don't think anything is appending while the list is being modified.</p>
  
  <p>Is this a thread issue? How can I find out? </p>
  
  <p>Here is the stacktrace:</p>
  
  <pre><code>0   _int_malloc malloc.c    3530    0x7ffff61c7410  
  1   __GI___libc_malloc  malloc.c    2924    0x7ffff61c9f95  
  2   QListData::detach(int)  /usr/lib/x86_64-linux-gnu/libQtCore.so.4    0   0x7ffff6cd397b  
  3   QList&lt;QString&gt;::detach_helper   qlist.h 709 0x412169    
  4   QList&lt;QString&gt;::detach_helper   qlist.h 725 0x411cf2    
  5   QList&lt;QString&gt;::detach  qlist.h 139 0x411e72    
  6   QList&lt;QString&gt;::begin   qlist.h 267 0x423610    
  7   QList&lt;QString&gt;::first   qlist.h 282 0x422dda    
  8   QList&lt;QString&gt;::takeFirst   qlist.h 490 0x422885    
  9   SB::ModuleCommunicator::handleMsg   ModuleCommunicator.cpp  116 0x41f9be    
  10  SB::ModuleCommunicator::onReadyRead ModuleCommunicator.cpp  393 0x421f4d    
  11  SB::ModuleCommunicator::qt_static_metacall  moc_ModuleCommunicator.cpp  52  0x435e1e    
  12  QMetaObject::activate(QObject*, QMetaObject const*, int, void**)    /usr/lib/x86_64-linux-gnu/libQtCore.so.4    0   0x7ffff6dc9281  
  13  QextSerialPortPrivate::_q_canRead   qextserialport.cpp  313 0x40c505    
  14  QextSerialPort::qt_static_metacall  moc_qextserialport.cpp  97  0x40dbfa    
  15  QMetaObject::activate(QObject*, QMetaObject const*, int, void**)    /usr/lib/x86_64-linux-gnu/libQtCore.so.4    0   0x7ffff6dc9281  
  16  QSocketNotifier::activated(int) /usr/lib/x86_64-linux-gnu/libQtCore.so.4    0   0x7ffff6e162fe  
  17  QSocketNotifier::event(QEvent*) /usr/lib/x86_64-linux-gnu/libQtCore.so.4    0   0x7ffff6dd260b  
  18  QApplicationPrivate::notify_helper(QObject*, QEvent*)   /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0   0x7ffff72d7894  
  19  QApplication::notify(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0   0x7ffff72dc713  
  20  QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtCore.so.4    0   0x7ffff6db4e9c  
  ... &lt;More&gt;  
  </code></pre>
  
  <p><strong>UDPATE:</strong></p>
  
  <p>So it seems I have a transient error here. Now it crashed at </p>
  
  <pre><code>for (int i = 0; i &lt; msgBuffer-&gt;size(); i++) {
  </code></pre>
  
  <p>with msgBuffer being yet another QStringList member of my Class. This piece of code is in the 'onReadyRead()' Slot that gets called when QExtSerialPort has data for me. 
  So I think the error is related to that package. </p>
  
  <p>I'm using Qt 4.8 on Ubuntu 12.04 with QExtSerialPort v1.2rc from <a href="https://code.google.com/p/qextserialport" rel="nofollow">https://code.google.com/p/qextserialport</a></p>