的QDataStream << and >>運算符我有一個目的,我想能夠讀取並從操作QDataStream寫入/。標題如下:重載用於用戶定義類型
class Compound
{
public:
Compound(QString, QPixmap*, Ui::MainWindow*);
void saveCurrentInfo();
void restoreSavedInfo(QGraphicsScene*);
void setImage(QPixmap*);
QString getName();
private:
QString name, homeNotes, addNotes, expText;
Ui::MainWindow *gui;
QPixmap *image;
struct NMRdata
{
QString hnmrText, cnmrText, hn_nmrText, hn_nmrNucl, notes;
int hnmrFreqIndex, cnmrFreqIndex, hn_nmrFreqIndex,
hnmrSolvIndex, cnmrSolvIndex, hn_nmrSolvIndex;
}*nmr_data;
struct IRdata
{
QString uvConc, lowResMethod,
irText, uvText, lowResText, highResText,
highResCalc, highResFnd, highResFrmla,
notes;
int irSolvIndex, uvSolvIndex;
}*ir_data;
struct PhysicalData
{
QString mpEdit, bpEdit, mpParensEdit, bpParensEdit,
rfEdit, phyText, optAlpha,
optConc, elemText, elemFrmla,
notes;
int phySolvIndex, optSolvIndex;
}*physical_data;
};
對於所有意圖和目的,類只是充當將QString和QPixmap的極少數的抽象。理想情況下,我將能夠到的QList寫入操作QDataStream,但我不完全知道如何去這樣做。
如果操作符重載是一個合適的解決方案,會寫像
friend QDataStream& operator << (QDataStream&,Compound) { ... }
代碼是一個潛在的解決方案嗎?我非常樂於提供建議!請讓我知道是否需要進一步澄清。
「意圖和目的」 – 2012-01-09 21:10:24