Important: Please read the Qt Code of Conduct -

QAudioInput Device State Change

  • Hey guys,

    I've hit a bit of a roadblock with the QAudioInput class trying to figure how to handle state changes. This is certainly platform-specific but I'm trying to figure out a way to make some changes to my QAudioInput device pointer if the actual audio device is disabled.

    In windows 10, under input devices, you can enable or disable a device (let's say the Stereo Mix / sound card input). If I understand the documentation correctly, I should be able to use the stateChanged signal to make changes:

    void AudioInputExample::handleStateChanged(QAudio::State newState)
        switch (newState) {
            case QAudio::StoppedState:
                if (audio->error() != QAudio::NoError) {
                    // Error handling
                } else {
                    // Finished recording
            case QAudio::ActiveState:
                // Started recording - read from IO device
                // ... other cases as appropriate

    So far when I disable the device I get this error:

    QAudioInput: failed to prepare block 0,err=6

    And there seems to be no way of deleting the QAudioInput object handling the device and recreating it since I never know when it's gone caput.

    I also tried messing around with QIODevice's aboutToClose() signal but that object is also the strong silent type...

    Anyone have experience doing this sort of thing on Windows or their own OS? Any thought would be appreciated.

    Thanks a bunch!