我需要覆盖 QDataStream 的 >> 和 << 运算符。这是我的代码:
QDataStream &operator <<(QDataStream &out, const SScenarioEntry Entry)
{
out.writeRawData(Entry.EntryName, sizeof(Entry.EntryName));
out << Entry.Number;
out << Entry.Type;
out.writeRawData(Entry.RequestString, sizeof(Entry.RequestString));
out.writeRawData(Entry.AnswerString, sizeof(Entry.AnswerString));
out.writeRawData(Entry.AdditionalParams, sizeof(Entry.AdditionalParams));
out << Entry.Timeout;
return out;
}
QDataStream &operator >>(QDataStream &in, SScenarioEntry Entry)
{
in.readRawData(Entry.EntryName, sizeof(Entry.EntryName));
in >> Entry.Number;
in >> Entry.Type;
in.readRawData(Entry.RequestString, sizeof(Entry.RequestString));
in.readRawData(Entry.AnswerString, sizeof(Entry.AnswerString));
in.readRawData(Entry.AdditionalParams, sizeof(Entry.AdditionalParams));
in >> Entry.Timeout;
return in;
}
成功编译后,我得到一些像这样的误解:
first define here
In function `Z7qt_noopv':
multiple definition of `operator>>(QDataStream&, scnent)`
我有两个问题:
- 我必须如何定义 << 和 >> 运算符才能正确工作;
- 如果此代码正确,如何修复链接错误。
Tnx 寻求答案。