struct ColorText
{
ColorText() {}
QString m_text;
QColor m_color;
};
QDataStream& operator <<(QDataStream &dataStream, ColorText &colorText)
{
dataStream << colorText.m_color << colorText.m_text;
return dataStream;
}
QDataStream& operator >>(QDataStream &dataStream, ColorText &colorText)
{
dataStream >> colorText.m_color >> colorText.m_text;
return dataStream;
}
int main()
{
ColorText colorText;
colorText.m_color = Qt::red;
colorText.m_text = "Red";
QFile file("test.data");
if(!file.open(QIODevice::ReadWrite))
{
qDebug() << "file open false!";
return -1;
}
QDataStream dataStream(&file);
dataStream << colorText;
file.seek(0);
dataStream >> colorText;
qDebug() << colorText.m_text << colorText.m_color;
return 0;
}
"Red" QColor(ARGB 1, 1, 0, 0)