我有一个这种形式的.ini文件:
#init file:
[files]
fileAmount=2
file1=string1, string2, 0
file2=string1, string2, 1
//cpp file:
settings=new QSettings(QString(":resources/configuration"), QSettings::IniFormat);
int n=set("files/fileAmount").toInt();
for(int i=1; i<=n; i++){
QStringList list=settings->value("files/file"+QString::number(i)).toStringList();
out<<list[0]<<" "<<list[1]<<" "<<list[2]<<endl;
}
//output:
string1 string2 0
string1 string2 1
有没有办法将空格设置为QStringList而不是komma的分隔符?
即有这个文件:
#init file:
[files]
fileAmount=2
file1=string1 string2 0
file2=string1 string2 1
获得相同的输出?
答案 0 :(得分:1)
Ini文件:
C:\ Users \用户名\应用程序数据\漫游\ MYORG \ MYAPP.INI
[files]
file1=string1 string2 0
ini文件中空格分隔的字符串列表的示例代码:
#include <QCoreApplication>
#include <QStringList>
#include <QSettings>
#include <QDebug>
void readSettings();
void writeSettings();
QStringList list;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSettings::setDefaultFormat(QSettings::IniFormat);
qApp->setApplicationName("MyApp");
qApp->setOrganizationName("MyOrg");
readSettings();
qDebug() << list;
writeSettings();
return a.exec();
}
void readSettings()
{
// read a space delimited value from QSettings string
// into a stringlist
QSettings s;
s.beginGroup("files");
QString temp = s.value("file1","string1 string2 0").toString();
list << temp.split(" ");
s.endGroup();
}
void writeSettings()
{
// write a space delimited value from QStringList
QSettings s;
s.beginGroup("files");
s.setValue("file1",list.join(" "));
s.endGroup();
}
输出:
("string1", "string2", "0")
希望有所帮助。