Writing my own object to a binary file.
Hi,
I want to write my own object to the binary file. But I receive the message:
Quote:
C:\Qt\Qt5.1.1\5.1.1\mingw48_32\include\QtCore\qdat astream.h:300: error: no match for 'operator<<' (operand types are 'QDataStream' and 'const User')
s << *it;
^
Code:
void Dialog::on_btnWrite_clicked()
{
QString nike
= ui
->wleNike
->text
();
QString password
= ui
->wlePassword
->text
();
QString firstName
= ui
->wleFirstName
->text
();
QString lastName
= ui
->wleLastName
->text
();
int age = ui->wspAge->text().toInt();
User user;
user.nike = nike;
user.password = password;
user.firstName = firstName;
user.lastName = lastName;
user.age = age;
QVector<User> users;
users.push_back(user);
out << users;
file.flush();
file.close();
}
Thank you!
Re: Writing my own object to a binary file.
You need to provide the operator<<() and operator>>() implementation for your User class. Its prototype looks like:
Each should do whatever is necessary to save/restore the internal state of the User object.