Your syntax is all wrong. The first field in each entry is the index, the second the name of the value, and (you are completely missing this) the value itself comes after an equal sign. You are also missing the size attribute.
This defines a 6-element array called StageNum, where each element has a value called "cy1" (test.ini):
[Config]
Number1=156
Number2=4
[StageNum]
size = 6
0/cy1 = 7
1/cy1 = 2
2/cy1 = 5
3/cy1 = 2
4/cy1 = 3
5/cy1 = 0
[Config]
Number1=156
Number2=4
[StageNum]
size = 6
0/cy1 = 7
1/cy1 = 2
2/cy1 = 5
3/cy1 = 2
4/cy1 = 3
5/cy1 = 0
To copy to clipboard, switch view to plain text mode
and this will read it:
#include <QCoreApplication>
#include <QSettings>
#include <QDebug>
int main(int argc, char *argv[])
{
int arySize = m4Settings.beginReadArray("StageNum");
qDebug() << "arySize =" << arySize;
for (int vL = 0; vL < arySize; vL ++)
{
m4Settings.setArrayIndex(vL);
qDebug()
<< "index =" << vL
<< "cy1 =" << m4Settings.value("cy1","0").toInt();
}
m4Settings.endArray();
return app.exec();
}
#include <QCoreApplication>
#include <QSettings>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QSettings m4Settings("test.ini", QSettings::IniFormat);
int arySize = m4Settings.beginReadArray("StageNum");
qDebug() << "arySize =" << arySize;
for (int vL = 0; vL < arySize; vL ++)
{
m4Settings.setArrayIndex(vL);
qDebug()
<< "index =" << vL
<< "cy1 =" << m4Settings.value("cy1","0").toInt();
}
m4Settings.endArray();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks