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 :
char name[256];
gethostname(name, 256);
path.append(name);
path.append(".ini");
if(!licenseFile.exists())
{
std::cout << "file doesn't exist" << std::endl;
path.clear();
for (int i = 0; i < files.size(); i++)
{
QFile file(directory.
absoluteFilePath(files
[i
]));
std::cout << files[i].toStdString() << std::endl;
line = in.readLine();
if (!line.
compare(QString(";3a0795c35a1afa904bc611b193376d33").
trimmed())) { path = files[i];
std::cout << "This is the file >>>>>>>>>>>>>>>>>>>>>" << files[i].toStdString() << endl;
file.close();
break;
}
file.close();
}
}
}
cout << iniFile.value("machine/Name").toString().toStdString() << endl;
char name[256];
gethostname(name, 256);
QString path("/certs/INI/");
path.append(name);
path.append(".ini");
QFile licenseFile(path);
if(!licenseFile.exists())
{
std::cout << "file doesn't exist" << std::endl;
QDir directory = QDir(QString("/certs/INI/"));
QStringList files;
path.clear();
files = directory.entryList(QStringList("*.ini"),QDir::Files | QDir::NoSymLinks);
for (int i = 0; i < files.size(); i++)
{
QFile file(directory.absoluteFilePath(files[i]));
std::cout << files[i].toStdString() << std::endl;
if (file.open(QIODevice::ReadOnly)) {
QString line;
QTextStream in(&file);
line = in.readLine();
if (!line.compare(QString(";3a0795c35a1afa904bc611b193376d33").trimmed())) {
path = files[i];
std::cout << "This is the file >>>>>>>>>>>>>>>>>>>>>" << files[i].toStdString() << endl;
file.close();
break;
}
file.close();
}
}
}
QSettings iniFile(path,QSettings::IniFormat);
cout << iniFile.value("machine/Name").toString().toStdString() << endl;
To copy to clipboard, switch view to plain text mode
Bookmarks