Important: Please read the Qt Code of Conduct -

QT audioinput example program, QAudioInput, AudioInfo, difference between emit(update) and connect-SLOT-SIGNAL(activated)

  • Hi

    In my audio input-output program (based on QT multimedia example "audioinput" and "audiooutput") I'm trying to stop the audioinput data flow, resulting in run time problem. When using the orginal QT "audioinput" program I got same run time problem.

    Here is some code snippets from orginal QT "audioinput" with only 3 added lines, comments.

    In deviceChanged() there are two stops. The stops are working well in deviceChanged().

    If using the stops inside refreshDisplay(), ie. use first buffer/m_level from writeData() then stop the m_audioInfo and m_audioInput, via emit update(), problem arise.

    If only enabling "Adding 1" in code you got a lot of "QAudioInput: IOError" in QT Output.
    If only enabling "Adding 2" in code you got "QAudioInput: failed to prepare block 0,err=5" in QT Output.
    If only enabling "Adding 3" in code the audioinput data flow is actually suspended. But i want having it stopped of other reason.

    Have I missed something? Why can't you enable m_audioInfo->stop() and/or m_audioInput->stop() in refreshDisplay()?
    Why will m_audioInput->suspend() work?

    What is the major difference of signal [emit(update)] and emit signal from [connect-m_devicebox-SIGNAL(activated)-SLOT]?

    Thank You

    qint64 AudioInfo::writeData(const char *data, qint64 len)
    maxValue = qMin(maxValue, m_maxAmplitude);
    m_level = qreal(maxValue) / m_maxAmplitude;
    emit update();
    return len;
    connect(m_audioInfo, SIGNAL(update()), SLOT(refreshDisplay()));
    connect(m_deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int)));
    void InputTest::refreshDisplay()

    //m_audioInfo->stop();// Added 1
    //m_audioInput->stop(); // Added 2
    //m_audioInput->suspend(); // Added 3


    void InputTest::deviceChanged(int index)
    m_audioInfo->stop(); // Used here
    m_audioInput->stop(); // Used here
    delete m_audioInput;

    m_device = m_deviceBox->itemData(index).value<QAudioDeviceInfo>();


Log in to reply