Hey,

I want to open a INI file, standard the file name is the hostname of the pc .ini. But must somebody change this I want to look in every INI file and examine the first line. No problems there. The problems start when I founded the file with the string I'm looking for and I want to use this with QSettings. Must I close the QTrxtstream or release it ? Can somebody give me some help ? Thanks a lot, this is the code I'm using :

Qt Code:
  1. char name[256];
  2. gethostname(name, 256);
  3.  
  4. QString path("/certs/INI/");
  5. path.append(name);
  6. path.append(".ini");
  7. QFile licenseFile(path);
  8.  
  9. if(!licenseFile.exists())
  10. {
  11. std::cout << "file doesn't exist" << std::endl;
  12. QDir directory = QDir(QString("/certs/INI/"));
  13. QStringList files;
  14. path.clear();
  15. files = directory.entryList(QStringList("*.ini"),QDir::Files | QDir::NoSymLinks);
  16.  
  17. for (int i = 0; i < files.size(); i++)
  18. {
  19. QFile file(directory.absoluteFilePath(files[i]));
  20.  
  21. std::cout << files[i].toStdString() << std::endl;
  22. if (file.open(QIODevice::ReadOnly)) {
  23. QString line;
  24. QTextStream in(&file);
  25.  
  26. line = in.readLine();
  27.  
  28. if (!line.compare(QString(";3a0795c35a1afa904bc611b193376d33").trimmed())) {
  29. path = files[i];
  30. std::cout << "This is the file >>>>>>>>>>>>>>>>>>>>>" << files[i].toStdString() << endl;
  31. file.close();
  32. break;
  33. }
  34. file.close();
  35. }
  36. }
  37. }
  38.  
  39. QSettings iniFile(path,QSettings::IniFormat);
  40.  
  41. cout << iniFile.value("machine/Name").toString().toStdString() << endl;
To copy to clipboard, switch view to plain text mode