Hello everyone, there is a structure

struct data{ QString engRegion; QString rusRegion; //.. } 

Tried to write data as follows:

 data test; //.. QFile f("D:\\test.json"); f.open(QFile::WriteOnly); QDataStream out(&f); out << test; 

But unfortunately this does not work. So how can you write a structure to a file? I really hope for your help, thanks in advance!

    1 answer 1

    It is necessary to overload the operators << and >> for your structure for QDataStream . Something like that:

     QDataStream &operator <<(QDataStream &stream, const data &A){ stream << engRegion; stream << rusRegion; ... return stream; } QDataStream &operator >>(QDataStream &stream, data &A){ stream >> engRegion; stream >> rusRegion; ... return stream; } 
    • I thank, I had previously seen this method, but did not know how to apply it. Now everything is possible. And be sure to write A.engRegion, etc. every time. or is there something like delphi with? - Malice
    • @Malice, did not understand the question, please clarify - Shadasviar