[Qt-interest] Correct way to overload custom class << and >> operators for use with QDataStream
Jaco Naude
naude.jaco at gmail.com
Tue May 4 12:35:09 CEST 2010
Hi
I believe this is a stupid question, but I can't seem to figure it
out. I have a class called ObserverRelationalTable for which I
overload the << and >> operators.
For your reference, the header file is located here:
http://pastebin.com/7An5zSGu
And the source file is here:
http://pastebin.com/624dsWri
This class is part of a library and when I use the overloaded
operators in the same library everything works. When I attempt to use
the overloaded operators in a different library I get the following
error:
undefined reference to `operator<<(QDataStream&,
Qtilities::ObjManagement::ObserverRelationalTable&)'
To work around it I've included the .cpp file where I use it rather
than the .h file as shown below:
//#include <ObserverRelationalTable.h>
#include <ObserverRelationalTable.cpp>
But I know that this is just a hack and not a solution to the problem,
and the compiler gives these warnings as well:
warning: 'int Qtilities::ObjManagement::ObserverRelationalTable::getSpecificParent(QObject*)
const' redeclared without dllimport attribute after being referenced
with dll linkage
I've also tried to declare the overloaded operator implementations in
the header file and not the source, but this results in compilation
errors because the functions are defined multiple times in my project.
Thus I believe I'm missing the point and I'm not using the operator
overloads as they should be used.
Any tips would be much appreciated,
Thanks,
Jaco
More information about the Qt-interest-old
mailing list