0
votes

I have a QList contains a list of OpenCv::Mat. I'd like to write the QList to a file and read a file into a QList with QDataStream.

Here is part of my code:

// Variables declarations
QList<Mat> myList;
cv::Mat someData;
QString fileName = "list.dat";
QFile file(fileName);
QDataStream out(&file);
QDataStream in(&file);

// Storing some data into the list
myList.append(someData);
myList.append(someData);
myList.append(someData);

// Writing the list to a file
file.open(QIODevice::WriteOnly);
out << myList;
file.close();

// Reading a file to the list
file.open(QIODevice::ReadOnly);
in >> myList;
file.close();

And I received two errors:

error: C2678: binary '>>': no operator found which takes a left-hand operand of type 'QDataStream' (or there is no acceptable conversion)

error: C2678: binary '<<': no operator found which takes a left-hand operand of type 'QDataStream' (or there is no acceptable conversion)

Any suggestions?

1
QDataStream & operator>>() has no overload for QList<Mat>. you have to push_back (or so) in a loop...user1810087
You must provide the two operators your self, they should have a signature like these: QDataStream& operator>>(QDataStream&, const QList<Mat>&); and QDataStream& operator<<(QDataStream&, const QList<Mat>&);Jonas
You only need operators for the Mat type, Qt knows how to serialize QList.dtech

1 Answers

1
votes

You need to provide those two operators for your custom type Mat :

QDataStream & operator<<(QDataStream &out, const Mat& mat)
QDataStream & operator>>(QDataStream &in, Mat& mat)