c++qtinheritanceqfileqiodevice

Why I can't reimplement methode from QIODevice when base class is QFile?


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!!


Solution

  • 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;