title: Qt - how to record and play sound simultaneously
body: <p>I posted this question on the Qt forum, but got no answers. That's why I am posting it here. </p>
  
  <p>I wanted to know is there any way to record and play sound at the same time in Qt. I want to record sound from a microphone and at the same time I want to play it in the speaker/headphone.</p>
  
  <p>Is there any way to do this in Qt? Or do I need to use any other library?</p>
  
  <p>It would be great if the solution is cross-platform (I need to cover windows, linux and mac). If it isn't possible, then a linux solution will do.</p>
  
  <p>I am using Qt 4.7 by the way.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>My latest implementation is given <a href="http://pastebin.com/n7e9KREA" rel="nofollow noreferrer">here</a>. I have created a sub-class of the <a href="https://doc.qt.io/qt-5/qiodevice.html" rel="nofollow noreferrer">QIODevice</a> and re-implemented its <a href="https://doc.qt.io/qt-5/qiodevice.html#writeData" rel="nofollow noreferrer">writeData</a> and <a href="https://doc.qt.io/qt-5/qiodevice.html#readData" rel="nofollow noreferrer">readData</a> method so that reading and writing can be done with a circular buffer. I have done this as per <a href="http://developer.qt.nokia.com/forums/viewthread/10653/#60143" rel="nofollow noreferrer">this suggestion</a>. This code also doesn't work because the <a href="https://doc.qt.io/qt-5/qaudiooutput.html" rel="nofollow noreferrer">QAudioOutput</a> instance faces <code>Underrun Error</code>, which according to <a href="https://doc.qt.io/qt-5/qaudio.html#Error-enum" rel="nofollow noreferrer">this documentation</a> means - </p>
  
  <blockquote>
    <p>Audio data is not being fed to the audio device at a fast enough rate</p>
  </blockquote>
  
  <p>I have applied a hack to solve this problem temporarily. In the <code>outputStateChanged</code> method, I am checking to see if the state of the output has changed to <code>IDLE</code> and if it has, I am again calling <code>start()</code> method, specifying the common buffer. I don't want to use this as a permanent solution because it feels really hacky and because I am swallowing an error without properly investigating its reasons.</p>
  
  <p>What should I do to solve this problem?</p>
  
  <p>I also tried to solve this using <a href="https://doc.qt.io/qt-4.8/phonon-module.html" rel="nofollow noreferrer">Phonon</a> but failed because I do not have sufficient knowledge of this module.</p>