I’m porting a app, that saves and loads setting to a file using QFile. I’m not using QSettings and a ini file, because I’m using serialization, wich I believe is not supported by QSettings. However the file fails to save. I’m guessing it’s because I’m using the app current location, wich probably doesnt allow saving.
//loading in the constructor
QFile file("conversions.dat");
if (file.open(QIODevice::ReadOnly)) // if file exists reads from file
{
QDataStream in(&file);
in>>m_CategoriesUnits_List;
in>>current_category_index;
file.close();
//QMessageBox::about(0,"","File does exist.");
}
else //if file does not exists reads from defaul constructor settings
{
//QMessageBox::about(0,"","File dont exist.");
loadInitialConversions();
}
//saving in the destructor
QFile file("conversions.dat");
if (file.open(QIODevice::WriteOnly))
{
QDataStream out(&file); // we will serialize the data into the file
out<<m_CategoriesUnits_List;
out<<current_category_index;
file.close();
}
else
QMessageBox::about(0,"","Cant save file.");
Any ideias for a quick and dirty solution :) ?
↧