当 base class 是 QFile 时,为什么我不能从 QIODevice 重新实现方法?
Why I can't reimplement methode from QIODevice when base class is QFile?
当我的基础 class 是 QIODevice 时,我可以重新实现 writeData 和 readData,但是如果基础 class 是 QFile 则它不起作用。 OFile 的基class 是QFileDevice QFileDevice 的基class 是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
from xyseriesiodevice
仅在基数 class 为 QIODevice
时调用
谢谢!!
如果您没有包含 QFile 库,请尝试包含它。
尝试在方法签名后添加 "override" 关键字。
qint64 readData(char * data, qint64 maxSize) override;
qint64 writeData(const char * data, qint64 maxSize) override;
当我的基础 class 是 QIODevice 时,我可以重新实现 writeData 和 readData,但是如果基础 class 是 QFile 则它不起作用。 OFile 的基class 是QFileDevice QFileDevice 的基class 是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
from xyseriesiodevice
仅在基数 class 为 QIODevice
谢谢!!
如果您没有包含 QFile 库,请尝试包含它。 尝试在方法签名后添加 "override" 关键字。
qint64 readData(char * data, qint64 maxSize) override;
qint64 writeData(const char * data, qint64 maxSize) override;