config.h 804 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef CONFIG_H
  2. #define CONFIG_H
  3. #include <QFile>
  4. #include <QCoreApplication>
  5. class Config{
  6. public:
  7. Config(){ file->exists() ? load() : setMode(0);}
  8. ~Config(){
  9. file->close();
  10. delete file;
  11. }
  12. void setMode(int m) { mode = m; save(); }
  13. int getMode() {return mode;}
  14. private:
  15. int mode = 0;
  16. QFile * file = new QFile(QCoreApplication::applicationDirPath() + "/src/config.ini");
  17. void load(){
  18. file->open(QIODevice::ReadOnly | QIODevice::Text);
  19. mode = file->readAll().toInt();
  20. file->close();
  21. }
  22. void save(){
  23. file->open(QIODevice::WriteOnly | QIODevice::Text);
  24. QString a;
  25. a.setNum(mode);
  26. file->write(a.toUtf8());
  27. file->close();
  28. }
  29. };
  30. #endif // CONFIG_H