I am trying to implement a class inherited from QIODevice.
The QT The documentation says: Subclasses of QIODevice are only required to implement the protected readData() and writeData() functions
I tried to create a basic dummy class that does not do much other than printing the function, here is the code:
class dummyClass : public QIODevice
{
Q_OBJECT
Q_DISABLE_COPY(dummyClass)
public:
explicit dummyClass( QObject *parent = 0): QIODevice(parent)
{
qDebug() << __FUNCTION__ <<endl;
}
protected:
qint64 readData(char *data, qint64 len)
{
qDebug() << __FUNCTION__ <<endl;
return 0;
}
qint64 writeData(const char *data, qint64 maxSize)
{
qDebug() << __FUNCTION__ <<endl;
return 0;
}
};
This is the code that checks the class:
dummyClass try_file;
try_file.write("hello to all the good people");
try_file.close();
When I run the code I get the following output:
dummyClass ::dummyClass
QIODevice::write (a): device not open
In other words, what happens is that the class turns to the original WRITE function and instead of redirecting the call to writeData as the documentation says, it's performs actions that obstruct the writing.
Can anyone show me where is my mistake? (Assuming I do not want to implement all the READ and WRITE functions in the QIODevice class myself)
Aucun commentaire:
Enregistrer un commentaire