jahsiotr
20th January 2013, 11:52
Hello,
I am trying to overload operators << and >> for QDataStream and my class. I checked some tutorials and have been trying to use them for my issue and got it almost right. When I write to a file I believe it works properly as I checked a file with binary editor. It surely saves QStrings properly. I can't tell anything about QDate and QTime variables as they don't appear in understandable way in Hex Fiend. Also I am aware that constructor is not used properly as when it isn't commented out it makes my app crash. So any hints to make it proper would be greatly appreciated.
QDataStream &operator>>(QDataStream &in, Task &task) {
bool isDone;
QString name;
QString description;
QDate dayClicked;
QTime start;
QTime end;
bool neededReminder;
QDateTime reminderTime;
quint32 time;
in >> name >> description >> dayClicked >> start >> end >> reminderTime >> isDone >> neededReminder >> time;
qDebug() << name << description << dayClicked.toString() << start.toString() << end.toString()
<< reminderTime.toString() << isDone << neededReminder << time;
task = Task(isDone, name, description, dayClicked, start, end, (int)time, neededReminder);
return in;
}
What qDebug is returning: "" "" "" "00:00:00" "00:00:00" "" false false 0
I am trying to overload operators << and >> for QDataStream and my class. I checked some tutorials and have been trying to use them for my issue and got it almost right. When I write to a file I believe it works properly as I checked a file with binary editor. It surely saves QStrings properly. I can't tell anything about QDate and QTime variables as they don't appear in understandable way in Hex Fiend. Also I am aware that constructor is not used properly as when it isn't commented out it makes my app crash. So any hints to make it proper would be greatly appreciated.
QDataStream &operator>>(QDataStream &in, Task &task) {
bool isDone;
QString name;
QString description;
QDate dayClicked;
QTime start;
QTime end;
bool neededReminder;
QDateTime reminderTime;
quint32 time;
in >> name >> description >> dayClicked >> start >> end >> reminderTime >> isDone >> neededReminder >> time;
qDebug() << name << description << dayClicked.toString() << start.toString() << end.toString()
<< reminderTime.toString() << isDone << neededReminder << time;
task = Task(isDone, name, description, dayClicked, start, end, (int)time, neededReminder);
return in;
}
What qDebug is returning: "" "" "" "00:00:00" "00:00:00" "" false false 0