Reputation: 186
I've created a two classes - Platform, and PlatformModel. PlatformModel contains a QVector.
I want to output information about each platform in the vector, so I overloaded the output operator of the Platform class like this:
QTextStream &operator <<(QTextStream &outStream, const Platform &platform);
which is defined as:
QTextStream &operator <<(QTextStream &outStream, const Platform &platform)
{
platform.print(outStream);
return outStream;
}
From the PlatformModel object, I iterate through the vector like this:
QVector<Platform*>::const_iterator i;
for(i = mPlatforms.begin(); i != mPlatforms.end(); ++i)
{
if ((*i)->mInclude)
{
outStream << (*i);
}
}
The QTextStream is eventually written out to a file, but all I'm getting is the address of the platform objects - the overridden operator<< function is not being called. What am I doing wrong?
Upvotes: 1
Views: 1508
Reputation: 5345
You need to deference iterator once more - because vector contains pointers, and iterator is pointer to vector element, i is double pointer.
outStream << *(*i);
Should work, or you can iterate through vector using Q_FOREACH
macro or index for simplicity.
Upvotes: 1