当基类是QFile时,为什么我不能从QIODevice重新实现方法?

时间:2018-04-08 20:29:09

标签: c++ qt inheritance qfile qiodevice

当我的基类是QIODevice时,我可以重新实现writeData和readData,但如果基类是QFile则它不起作用。 OFile的基类是QFileDevice,QFileDevice的基类是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);

致电

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

xyseriesiodevice仅在基类为QIODevice时调用

谢谢!

1 个答案:

答案 0 :(得分:0)

如果您没有包含QFile库,请尝试包含它。 尝试在方法签名后添加“override”关键字。

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