Advertisement
Guest User

load и save

a guest
Dec 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bool CoinsDatabase::save(const QString &filename)
  2. {
  3.     bool opened = false; //успешность открытия файла
  4.  
  5.     if (!filename.isEmpty())
  6.     {
  7.         QFile file(filename);
  8.         opened = file.open(QIODevice::WriteOnly);
  9.         modified = false;
  10.         QDataStream output(&file);
  11.  
  12.         output << db << ids << maxId;
  13.  
  14.         file.close();
  15.     }
  16.  
  17.     return opened;
  18. }
  19.  
  20. bool CoinsDatabase::load(const QString &filename)
  21. {
  22.     bool opened = false; //успешность открытия файла
  23.  
  24.     if (!filename.isEmpty()) //если имя файла не пустое
  25.     {
  26.         //создаем файл
  27.         QFile file(filename);
  28.  
  29.         //открываем файл только для чтения
  30.         opened = file.open(QIODevice::ReadOnly);
  31.  
  32.         if (opened)
  33.         { //если открыт успешно
  34.             modified = false;
  35.  
  36.             QDataStream output(&file);
  37.  
  38.             output >> db >> ids >> maxId;
  39.  
  40.             file.close();
  41.         }
  42.     }
  43.  
  44.     return opened;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement