Skip to content

Instantly share code, notes, and snippets.

@alex-pat
Created December 16, 2015 20:49
Show Gist options
  • Save alex-pat/8295126c40e270c50caf to your computer and use it in GitHub Desktop.
Save alex-pat/8295126c40e270c50caf to your computer and use it in GitHub Desktop.
QDataStream example
void Manager::saveData() {
QFile settings ("sbsettings");
if ( settings.open ( QIODevice::WriteOnly ) == false ) {
std::cerr << "Cannot open settings" << std::endl;
exit(1);
}
QDataStream stngs (&settings);
int size = profiles.size();
stngs << size
<< currentProfile;
for (int i = 0; i < size; i++)
stngs << *(profiles[i]);
}
void Manager::loadData() {
QFile settings ("sbsettings");
if ( settings.open ( QIODevice::ReadOnly ) == false ) {
std::cerr << "Cannot open settings" << std::endl;
exit(1);
}
QDataStream stngs (&settings);
int size;
stngs >> size
>> currentProfile;
for (int i = 0; i < size; i++) {
Profile* prof = new Profile;
stngs >> prof;
profiles.push_back( prof );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment