load a .dat file into a listwidget QT

the user inputs 3 different values into 3 text fileds and then hits a button that adds them all to a text file then loads what is in that text file into a listwidget.

that works fine no problems however i want to do the same using .dat file insteadof .txt here is my code

web = ui->txt_web->text();
username = ui->txt_username->text();
password = ui->txt_password->text();

QFile file("file.dat");
file.open(QIODevice::WriteOnly | QIODevice::Append);
QDataStream out(&file); // we will serialize the data into the file
out << "Website: " +web+ " " + "Username: " +username+ " " + "Password: " +password;

above shows the save function pretty sure thats all working fine however i have no idea how to load this data back into the list widget

QFile file2("file.dat");
file2.open(QIODevice::ReadOnly);
QDataStream in(&file2);
QString str;
in >> str;
std::cout<<str.toAscii().data()<<std::endl;

this works from a different button click (just as a test and prints to console just t check valeus are loading) this works fine too but i dont know how to get this code to make it go into a list widget as separate items

any help would be greatly appreciated
Assuming you're using Qt4, have a look at the QListWidget addItem(const QString& label) documentation - there's also the additems( const QStringList& labels ), if you have already built the list of strings from the lines in the file.
Topic archived. No new replies allowed.