我需要覆盖>>和<lt;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)`
我有两个问题:
- 我必须如何定义<lt;和>>操作员正确工作
- 如果这个代码是正确的,如何修复链接错误
Tnx获取答案。
这很奇怪,但通过划分函数公告和描述解决了问题。