Saving Qlist data in a mysql database
-
Tried this for the << operator:
QDataStream &operator<<(QDataStream &stream,const Anim_t &anim) { stream << anim.ts.msecsSinceStartOfDay() << anim.I; return stream; }
Got this error, what have I missed ?
anim.h:35:15: error: 'QDataStream& Anim::operator<<(QDataStream&, const Anim::Anim_t&)' must have exactly one argument
35 | QDataStream &operator<<(QDataStream &stream,const Anim_t &anim) -
-
It must be a free function, if it's a member of your struct then you have to remove
const Anim_t &anim
-
Ok implimented operators as free functions and everything now compiles, however on running the application the QByteArray is empty (example with one element in QList):
...
QDataStream &operator<<(QDataStream &stream, const Anim::Anim_t &anim)
{
stream << anim.ts.msecsSinceStartOfDay() << anim.I;
return stream;
}QDataStream &operator>>(QDataStream &stream, Anim::Anim_t &anim)
{
int t;
stream >> t >> anim.I;
anim.ts = QTime::fromMSecsSinceStartOfDay(t);
return stream;
}...
QByteArray array; QDataStream stream(array); for(int i=0;i<Animations.size();i++) { stream << Animations.at(i); } QByteArray tmp=qCompress(array,9); fprintf(stderr,"Binary Blob Animations (%lld) size %lld compressed size %lld\n",Animations.size(),array.size(),tmp.size());
...
Binary Blob Animations (1) size 0 compressed size 4
Any suggestions ?
Thanks -
@SMF-Qt said in Saving Qlist data in a mysql database:
QDataStream stream(array);
Please read: https://doc.qt.io/qt-5/qdatastream.html#QDataStream-3
"Use QDataStream(QByteArray*, int) if you want to write to a byte array." -
@SMF-Qt Then also please mark this topic as solved, thx.
-
If I may, there's no need for the loop, you should be able to directly stream the list object and not go manually with that loop.