Regarding Using QSettings to read INI File
-
@JonB Got it,thank you. I am getting in alphabetical order when I am using QMap. My Requirement is to get in the order the same as my .ini file. What should I do?
-
@poojakamshetty
hi
Well store them in a list instead. that will store them as added but you lose
the ability to lookup by key but maybe thats fine. -
@mrjj Hi,
If I store them in a list I think I won't get the output as key-value pair right? -
@poojakamshetty
Hi
Not if you only store a string but you could easily just do
QVector<QPair<QString, QString>> list;
or a similar structure to store both key and value in the same list. -
This post is deleted! -
@mrjj Hi
Okay, Got it Thank you.
I have a doubt. In the container, the values can be stored in any order or if they are not in the order as .ini file will that be any problem later? -
@poojakamshetty
Hi
They will be stored in same order as you add them so if you add them in the order you read them it should be as you want. (same order as in ini file) -
if they are not in the order as .ini file will that be any problem later?
The ini file/
QSettings
does not care about the order of entries. Only you seem to want this:My Requirement is to get in the order the same as my .ini file.
Why do you even need this?
-
This post is deleted! -
@poojakamshetty
It helps if you use code tags for posting this here.values.insert(childKey, settings.value(childKey).toString());
Don't you mean:
QVector<QPair<QString, QString>> values; ... values.insert(i, QPair<QString, QString>(childKey, settings.value(childKey).toString()));
?
Define yourself a type for
QPair<QString, QString>
and this will read easier. -
Hi,
Since you really want a specific order, wouldn't it be simpler to sort your container after loading it with data ? That way you would be a bit less depending on the storage format.
-
@SGaist
Hi
He wants same order as in the ini file so not sure we can sort it out by sorting ;)
Unless you have something magic in mind? -
@mrjj said in Regarding Using QSettings to read INI File:
@SGaist
Hi
He wants same order as in the ini file so not sure we can sort it out by sorting ;)
Unless you have something magic in mind?Nothing magic, but if order is important then maybe sorting the container be a better idea than relying on something that can be modified with a text editor.
-
@SGaist
Absolutely if the order has any logic to it.
Also I'm not sure poster will find QVector easy to access compared to a
map. -
@JonB using this I am getting error.
-
@poojakamshetty said in Regarding Using QSettings to read INI File:
I am getting error
Don't you think you should post the actual error?!
Or should we guess what the error is? -
@jsulm I am sorry, I thought I mentioned error.
main.cpp:29:13: error: no matching member function for call to 'insert'
qvector.h:147:10: note: candidate function not viable: requires 2 arguments, but 1 was provided
qvector.h:148:10: note: candidate function not viable: requires 2 arguments, but 1 was provided
qvector.h:235:21: note: candidate function not viable: requires 2 arguments, but 1 was provided
qvector.h:236:21: note: candidate function not viable: requires 2 arguments, but 1 was provided
qvector.h:149:10: note: candidate function not viable: requires 3 arguments, but 1 was provided
qvector.h:234:14: note: candidate function not viable: requires 3 arguments, but 1 was provided
This is an error.
values.insert(QPair<QString, QString>(childKey, settings.value(childKey).toString()));
At this line, I am getting that error. -
@poojakamshetty Please take a look at QVector documentation for insert() methods and fix your code. Hint: insert() has two parameters (as the error message already suggests).
-
Hi
Actually you might want to use append instead
https://doc.qt.io/qt-5/qvector.html#append
values.append(QPair<QString, QString>(childKey, settings.value(childKey).toString()));