QDataStream class/struct & stream operators
Hi everybody,
following problem:
I'm using a struct comparable to this one in my code:
Code:
#ifndef STRUCT_MYPOINT
#define STRUCT_MYPOINT
#include <QDataStream>
typedef struct MyPoint {
int x;
int y;
}MyPoint;
{
out << (qint32)p.x;
out << (qint32)p.y;
return out;
}
{
in >> (qint32)p.x;
in >> (qint32)p.y;
return in;
}
#endif
this struct is defined in a seperate *.h file, lets say "mypoint.h"
my code works fine if I compile it with Visual Studio .Net & Qt 4.4.0
now I also try to compile my code under a linux environment using qt 4.4.0 and gcc 4.2.0
now the same code won't compile anymore.
I get a long list of errors messages, with the important ones saying
no match for 'operator>>'
no match for 'operator<<'
searched the net for some kind of solution, but haven't found one.
only thing I learned is that I must add, at least, the following lines to my code:
added these lines to my struct:
Code:
#ifndef STRUCT_MYPOINT
#define STRUCT_MYPOINT
#include <QDataStream>
typedef struct MyPoint {
int x;
int y;
}MyPoint;
{
out << (qint32)p.x;
out << (qint32)p.y;
return out;
}
{
in >> (qint32)p.x;
in >> (qint32)p.y;
return in;
}
#endif
but the problem remains.
So what am I missing/doing wrong???
greetz
darksaga
Re: QDataStream class/struct & stream operators
side note: the typedef around the struct is not necessary in C++.
Code:
{
in >> (qint32)p.x;
in >> (qint32)p.y;
return in;
}
I would assume that you can't cast p.x to a value and stream into this value.
Probably something like
Code:
qint32 tmp;
in >> tmp;
p.x = tmp;
would be more appropriate.
Apart from that:
Please show us the code that produces the error messages and the complete error message, too.
And finally,
I suggest to just declare the output function in the header (and implement them in some .cpp file). Otherwise you will end up with multiple definitions of those functions and get linker errors.
HTH