Nominate our 2022 Qt Champions!

Open a microphone device with QAudioInput

  • Hello everybody,

    I try to open a microphone device under ubuntu like the tutorial :

    void AudioRecorder::startListening(){
        if(m_audioInput == NULL){
            // Select the device that I want
            QList<QAudioDeviceInfo> availableDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
            for(int i=0;i<availableDevices.size();i++){
                qDebug() <<;
                if(!"plughw:CARD=C525,DEV=0")){   //plughw:CARD=C525,DEV=0 plughw:CARD=r0,DEV=0
                    m_audioInputDevice =;
                    qDebug() << "Selected device :" << m_audioInputDevice.deviceName();
            // Check format is OK
                qWarning() << "Default format not supported, trying to use the nearest.";
                m_format = m_audioInputDevice.nearestFormat(m_format);
                qDebug() << "Codec:" << m_format.codec();
                qDebug() << "Channel count:" << m_format.channelCount();
                qDebug() << "Sample size:" << m_format.sampleSize();
                qDebug() << "Sample rate:" << m_format.sampleRate();
                // Initialisation du micro
                m_audioInput = new QAudioInput(m_audioInputDevice,m_format,this);
                m_audioInputIODevice = m_audioInput->start();
                qDebug() << m_audioInput->error();
                qDebug() << "Start listening event" << m_audioInputIODevice << m_audioInput;
            else {
                qCritical() << "Problem audio format";

    The problem is the fonction "m_audioInput->start();" return always null pointer and I have an error for connect "connect(m_audioInputIODevice,SIGNAL(readyRead()),this,SLOT(audioDataReady()));" :

    QObject::connect: Cannot connect (null)::readyRead() to AudioRecorder::audioDataReady()

    Type variables are :

    QAudioInput *m_audioInput;
    QIODevice   *m_audioInputIODevice;
    QAudioDeviceInfo    m_audioInputDevice;
    QAudioFormat    m_format; 

    If someone can tell me where is my mistake ...

    Thank a lot !

  • Lifetime Qt Champion

    I would also check the error stuff and see if it says
    If it gives QAudio::OpenError
    or why it cannot start.

    I assume that
    Does in fact fully work so its not a driver issue.

  • I check the error with :

    qDebug() << m_audioInput->error();

    return :


    I try to change the device and it works with alsa_input.pci-0000_00_1b.0.analog-stereo. But it's not the microphone that I want to used.
    I think the microphone i want to used, it is not detected by alsa library ...

    How can I do the detection of the microphone to alsa library ?

    Knowing the microphone is detected with the alsamixer application ...

  • In fact, when i use QAudioRecorder I must put "alsa:plughw:CARD=C525,DEV=0"and when i use QAudioInput I must put "alsa_input.usb-046d_HD_Webcam_C525_D01D63D0-00.analog-mono".

    Why ? And have not always the "alsa_input.usb ..." for all input device ...

  • Lifetime Qt Champion


    Did you try to enumarate all the available inputs ? Does the microphone appear in that list ?

  • Yes :

    default input device "alsa_output.0.analog-stereo.monitor"

    I think pulseaudio create :

    "alsa_output.0.analog-stereo.monitor"    // For stereo output
    "alsa_input.usb-046d_HD_Webcam_C525_D01D63D0-00-C525.analog-mono"    // For the microphone of my webcam CARD=C525

    But it does anything for the microphone CARD=r0 ....

    I don't know why ... Do you how to create a device with pulseaudio ?

Log in to reply