I am trying to write bit fields structure to file and then read it.
For example:
typedef struct{
ushort
a:4,
b:4,
c:4,
d:4;
} teststruct;
I try to write and read it like this
QDataStream &operator <<(QDataStream &st, const teststruct &a)
{
st <<a.a << a.b << a.c << a.d;
return st;
}
QDataStream &operator >>(QDataStream &st, teststruct &a)
{
st >>a.a >> a.b >> a.c >> a.d;
return st;
}
teststruct str1, str2;
str1.a = 1;
str1.b = 0;
str1.c = 1;
str1.d = 0;
QFile f("testfile");
f.open(QFile::WriteOnly);
QDataStream st(&f);
st << str1;
f.close();
f.open(QFile::ReadOnly);
QDataStream st(&f);
st >> str2;
f.close();
But in QDataStream::operator>>
I got an error
error: cannot bind bitfield 'a.teststruct::a' to 'quint16& {aka short unsigned int&}'
What can I do with >>
operator or maybe there is other way to read data to my structure?