我正在尝试在配置文件中搜索String,并且字符串匹配是否要删除键/值对。我从文件中获取qstringlist。 至于我试过的代码是
int main(int argc, char *argv[])
{
QSettings* settings= new QSettings("/home/sidheshwar/Desktop/temp.txt", QSettings::IniFormat);
settings->beginGroup("Profiles");
const QStringList childKeys = settings->childKeys();
QStringList Keys;
QStringList values;
QString user="db-host";
QString tempUser;
foreach (const QString &childKey, childKeys)
{
Keys << childKey;
values << settings->value(childKey).toString();
}
for(int i=0;i< Keys.length();i++){
if(user == values.at(i)){
qDebug() << " keys" << Keys[i] << endl;
tempUser=Keys[i];
}
qDebug() << " tempUser" << tempUser << endl;
}
return 0;}
我如何使用settings->remove(tempUser);
答案 0 :(得分:1)
在下面的示例中,我将向您展示如何从处理配置的文件中删除数据的示例。
执行前temp.ini 。
WHERE CONVERT(datetime, convert(varchar(10), a.paid_date))BETWEEN DateAdd(month,-6,b.startdate) and b.startdate
<强>的main.cpp 强>
[Profiles]
key1=db-host
key2=value2
key3=value3
输出:
执行后temp.ini
#include <QCoreApplication>
#include <QSettings>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSettings* settings= new QSettings("temp.ini", QSettings::IniFormat);
settings->beginGroup("Profiles");
const QStringList childKeys = settings->childKeys();
QStringList Keys;
QStringList values;
QString user="db-host";
foreach (const QString &childKey, childKeys)
{
Keys << childKey;
values << settings->value(childKey).toString();
}
for(int i=0;i< Keys.length();i++){
if(user == values.at(i)){
qDebug() << " keys" << Keys[i];
settings->remove(Keys[i]);
}
qDebug() << Keys[i] << values.at(i);
}
return a.exec();
}