0

when my base class is QIODevice I can reimplement writeData and readData, but if the base class is QFile it doesn't work. The base class of OFile is QFileDevice and the base class of QFileDevice is QIODevice:

//This works:
//class xyseriesiodevice : public QIODevice

//This doesn't work
class xyseriesiodevice : public QFile
{
    Q_OBJECT
public:
    explicit xyseriesiodevice(QXYSeries * series, QObject *parent = 0);

protected:
    qint64 readData(char * data, qint64 maxSize);
    qint64 writeData(const char * data, qint64 maxSize);

When calling

//m_device is of type xyseriesiodevice
//m_audioInput is of type QAudioInput    
m_device->open(QIODevice::WriteOnly);
m_audioInput->start(m_device);

writeData from xyseriesiodevice is only called when the base class isQIODevice

Thanks!!

  • 2
    It should work. Have you checked the result of the `open()` call? If the open fails then probably QAudioOutput won't call `writeData()`. – Aurélien Gâteau Apr 08 '18 at 22:33
  • FWIW I tried modifying the QT example program (at `qtmultimedia/examples/multimedia/audioinput`) so that its `AudioInfo` class subclass QFile rather than QIODevice, and after doing that (and after changing the AudioInfo::start() method to call open(stdout, QIODevice::WriteOnly)), I can see that AudioInfo::writeData() is being called at regular intervals with 4096-byte chunks of audio data. This is under MacOS/X with Qt 5.10.0. – Jeremy Friesner Apr 09 '18 at 04:58

1 Answers1

1

If you didn't include QFile library try including it. Try also adding "override" keyword after method signature.

qint64 readData(char * data, qint64 maxSize) override;
qint64 writeData(const char * data, qint64 maxSize) override;
rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
R. Mereu
  • 46
  • 3