I want to do the arithmetic mean of values of a buffer which I wanna to fill with QAudioInput.

I declare these objects:
Qt Code:
  1. QAudioFormat audioformat;
  2. QAudioInput *input;
  3. QIODevice *intermediario;
  4. QByteArray buffer;
To copy to clipboard, switch view to plain text mode 

I wrote this function for formatting audioformat:
Qt Code:
  1. void formatta_audio (QAudioFormat *formato)
  2. {
  3. formato->setFrequency(1000);
  4. formato->setSampleSize(8);
  5. formato->setCodec("audio/pcm");
  6. formato->setByteOrder(QAudioFormat::LittleEndian);
  7. formato->setSampleType(QAudioFormat::UnSignedInt);
  8. formato->setChannels(1);
  9. }
To copy to clipboard, switch view to plain text mode 

In the MainWindow costructor I wrote this:
Qt Code:
  1. QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
  2.  
  3. formatta_audio(&audioformat);
  4.  
  5. if (!info.isFormatSupported(audioformat))
  6. audioformat = info.nearestFormat(audioformat);
  7.  
  8. input= new QAudioInput (audioformat);
  9.  
  10. ui->setupUi(this);
To copy to clipboard, switch view to plain text mode 

I start the QaudioInput in this way:
Qt Code:
  1. intermediario = input->start();
  2. connect (intermediario,SIGNAL(readyRead()),this,SLOT(cattura()));
To copy to clipboard, switch view to plain text mode 

And stop the QaudioInput in this way:
Qt Code:
  1. input->stop();
To copy to clipboard, switch view to plain text mode 

"cattura()" function is this:
Qt Code:
  1. void MainWindow::cattura()
  2. {
  3.  
  4. qint64 Nbytesletti;
  5. qint64 i;
  6. qint64 media=0;
  7. qint64 bytescatturati;
  8.  
  9.  
  10. bytescatturati= intermediario->bytesAvailable();
  11.  
  12. if (bytescatturati>0)
  13. {
  14.  
  15. Nbytesletti= intermediario->read(buffer.data(),bytescatturati);
  16.  
  17. for (i=0;i<Nbytesletti;i++)
  18. {
  19. media+=(qint64)buffer.at(i);
  20. }
  21.  
  22. media/=Nbytesletti;
  23.  
  24. ui->label->setText(QString("%1").arg(media));
  25. }
  26.  
  27.  
  28. }
To copy to clipboard, switch view to plain text mode 

I've tried a lot of times but "intermediario->bytesAvailable()" return ever "0"

Why? What is the problem?