当我的基类是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
谢谢!!
最佳答案
如果您不包括QFile库,请尝试包括它。
尝试在方法签名后也添加“override”关键字。
qint64 readData(char * data, qint64 maxSize) override;
qint64 writeData(const char * data, qint64 maxSize) override;
关于c++ - 当基类是QFile时,为什么不能从QIODevice重新实现methode?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49722457/