title: Audio input example doesn't work - QAudioInput: IOError
body: <p>I am a freshgirl to Qt. (C++ as well)</p>
  
  <p>I saw an example from QAudioInput class reference, and in order to pass the compile I made a little change (all the difference you see from my code to the example is because of compile failed at first). </p>
  
  <p>I looked up a lot on the Internet, still got nothing. And the example <a href="http://doc.qt.io/archives/qt-4.7/multimedia-audioinput-audioinput-h.html" rel="nofollow">http://doc.qt.io/archives/qt-4.7/multimedia-audioinput-audioinput-h.html</a>
  does work. And I read it carefully, nothing different except mine is to save to a file, and that one is to save to a buffer.</p>
  
  <p>so, please help me with 1, what are the reasons to cause QAudioInput: IOError (I know there is problem on IO devices, but what is the problem?)
  2, how could I make the code work?</p>
  
  <p>Here are the code:</p>
  
  <pre><code>    //audioprocess.h
  #ifndef AUDIOPROCESS_H
  #define AUDIOPROCESS_H
  
  #include &lt;QAudioInput&gt;
  #include &lt;QFile&gt;
  #include &lt;QDebug&gt;
  #include &lt;QTimer&gt;
  #include &lt;QObject&gt;
  
  class audioprocess : public QObject
  {
    Q_OBJECT
  public:
    void startRecording();
  private slots:
    void stopRecording();
  private:
    QFile outputFile; // class member.
    QAudioInput *audioInput; // class member.
  };
  
  #endif // AUDIOPROCESS_H
  
  //----------------------------------------------
  //audioprocess.cpp
  
  
  #include "audioprocess.h"
  
  void audioprocess::startRecording()
  {
    outputFile.setFileName("/audio_qt.raw");
    outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate );
  
    QAudioFormat format;
    // set up the format you want, eg.
    format.setFrequency(8000);
    format.setChannels(1);
    format.setSampleSize(8);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);
  
    QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
    if (!info.isFormatSupported(format)) {
    qWarning()&lt;&lt;"default format not supported try to use nearest";
    format = info.nearestFormat(format);
    }
  
    audioInput = new QAudioInput(format,reinterpret_cast&lt;QObject*&gt;(this));
  
    QTimer::singleShot(100, reinterpret_cast&lt;QObject*&gt;(this), SLOT(stopRecording()));
    audioInput-&gt;start(&amp;outputFile);
    // Records audio for 3000ms
  }
  
  void audioprocess::stopRecording()
  {
    audioInput-&gt;stop();
    outputFile.close();
    delete audioInput;
  }
  //--------------------------------------------------------
  
  //main.cpp
  #include &lt;QtGui/QApplication&gt;
  #include "audioprocess.h"
  
  int main(int argc, char *argv[])
  {
    QApplication a(argc, argv);
    audioprocess audiorecord;
    audiorecord.startRecording();
  
    return a.exec();
  }
  </code></pre>