0
votes

qt5.7 on fedora

Checked this audio-to-chart example and found that QIODevice::writeData is used for reading mic input. Since it works and data from mic is being plotted, the function is obviously not writing but reading the data. But QIODevice doc page clearly states:

[pure virtual protected] qint64 QIODevice::writeData(const char *data,
qint64 maxSize) 

Writes up to maxSize bytes from data to the device. Returns the number of bytes written, or -1 if an error occurred.

So my question is why/how does that work?

1

1 Answers

1
votes

Looking at the code, the only QIODevice is XYSeriesIODevice which is responsible for plotting the data.

You also have a QAudioInput for reading from the mic.

XYSeriesIODevice::writeData() is called by the QAudioInput to write data to the chart.

m_audioInput = new QAudioInput(inputDevices,formatAudio, this);

m_device = new XYSeriesIODevice(m_series, this);
m_device->open(QIODevice::WriteOnly);

m_audioInput->start(m_device);

void QAudioInput::start(QIODevice *device)

Starts transferring audio data from the system's audio input to the device. The device must have been opened in the WriteOnly, Append or ReadWrite modes.