Advertisement
Guest User

Untitled

a guest
May 4th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3. #include <QDebug>
  4. #include <QFile>
  5.  
  6. QPixmap load_cache(QString path)
  7. {
  8.     QFile file(path);
  9.     if(!file.open(QFile::ReadOnly)) {
  10.         qDebug() << file.errorString();
  11.         throw 1;
  12.     }
  13.     QDataStream stream(&file);
  14.     stream.setVersion(QDataStream::Qt_4_7);
  15.     QPixmap pix;
  16.     stream >> pix;
  17.     return pix;
  18. }
  19.  
  20. bool save_cache(QString path, QPixmap pix)
  21. {
  22.     QFile file(path);
  23.     if(!file.open(QFile::WriteOnly | QFile::Truncate))  {
  24.         qDebug() << file.errorString();
  25.         return false;
  26.     }
  27.     QDataStream stream(&file);
  28.     stream.setVersion(QDataStream::Qt_4_7);
  29.     stream << pix;
  30.     return true;
  31. }
  32.  
  33. void save_pixmap(QString path, QPixmap pix)
  34. {
  35.     qDebug() << "saving to " << path;
  36.     QFile file(path);
  37.     pix.save(&file, "PNG");
  38. }
  39.  
  40. int main(int argc, char *argv[])
  41. {
  42.     QApplication a(argc, argv);
  43.     MainWindow w;
  44.     w.show();
  45.  
  46.     QString path = "/tmp/";
  47.     QString cache = path + "cache.cache";
  48.  
  49.     const int init = 0;
  50.     int i = init;
  51.     QPixmap pix(path + "logo" + QString::number(i) + ".png");
  52.     for (; i < init + 1000; ++i) {
  53.         save_cache(cache, pix);
  54.         pix = load_cache(cache);
  55.     }
  56.     save_pixmap(path + "logo" + QString::number(i) + ".png", pix);
  57.  
  58.     return a.exec();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement