2016-04-30 59 views
0

我需要覆蓋>>和< <運算符QDataStream。這裏是我的代碼:
正確覆蓋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; 
} 

全成編譯後,我得到一些misunderstandable象這樣的錯誤:

first define here 
In function `Z7qt_noopv': 
multiple definition of `operator>>(QDataStream&, scnent)` 

我有2個問題:

  1. 我該怎麼定義< <和>>運營商的正確工作;
  2. 如果此代碼是正確的,如何解決鏈接錯誤。


Tnx for answers。

回答

0

這很奇怪,但問題是通過分解函數公告和描述來解決的。