Unsolved how can i parser the .ini file?
-
@victor-wang What about QSettings? http://doc.qt.io/qt-5/qsettings.html
-
@victor-wang Use http://doc.qt.io/qt-5/qsettings.html#QSettings-2 and pass QSettings::IniFormat as first parameter.
-
@jsulm
Do you have any example for me?
It is too abstract for me to read. -
@victor-wang Please read documentation (http://doc.qt.io/qt-5/qsettings.html) there are examples:
QCoreApplication::setOrganizationName("MySoft"); QCoreApplication::setOrganizationDomain("mysoft.com"); QCoreApplication::setApplicationName("Star Runner"); ... QSettings settings; int margin = settings.value("editor/wrapMargin").toInt();
-
@jsulm
For example, i have an .ini file called poduct.ini.
So if i want to set this one how can i possible set?What is the meaning of organization name,organization Domain and application name stand for?
-
@victor-wang Please read documentation, there is a reason why Qt provides documentation: http://doc.qt.io/qt-5/qsettings.html#QSettings-3
You can ignore Organization/Domain/ApplicationName in your case.QSettings settings("my_ini_file.ini", QSettings::IniFormat);
-
@jsulm
I have saw this but that let me doubt how can it know where my file is put?
My file can be located at anywhere but why can this function find the directly? -
@victor-wang Since it is your file you have to know where it is and pass the whole path:
QSettings settings("/PATH_TO_MY_INI_FILE/my_ini_file.ini", QSettings::IniFormat);
As alternative you can let Qt handle this if you pass Organization/Domain/ApplicationName. Again: read documentation.
-
if the ini-file is not in the default path, you have to modify
"my_ini_file.ini"
in such a way that it describes the path of the file.
This is the case for all file related operations fyi.QSettings settings("c:/Folder1/Folder2/..../my_ini_file.ini", QSettings::IniFormat);
-
This post is deleted! -
@J.Hilk
Are these path be the meaning of your default path?$HOME/.config/MySoft/Star Runner.ini (Qt for Embedded Linux: $HOME/Settings/MySoft/Star Runner.ini) $HOME/.config/MySoft.ini (Qt for Embedded Linux: $HOME/Settings/MySoft.ini) /etc/xdg/MySoft/Star Runner.ini /etc/xdg/MySoft.ini
-
Quote from the docu:
Platform-Specific Notes
Locations Where Application Settings Are Stored
As mentioned in the Fallback Mechanism section, QSettings stores settings for an application in up to four locations, depending on whether the settings are user-specific or system-wide and whether the settings are application-specific or organization-wide. For simplicity, we're assuming the organization is called MySoft and the application is called Star Runner.
On Unix systems, if the file format is NativeFormat, the following files are used by default:
$HOME/.config/MySoft/Star Runner.conf (Qt for Embedded Linux: $HOME/Settings/MySoft/Star Runner.conf)
$HOME/.config/MySoft.conf (Qt for Embedded Linux: $HOME/Settings/MySoft.conf)
/etc/xdg/MySoft/Star Runner.conf
/etc/xdg/MySoft.confThe answer therefore is
yes
-
@J.Hilk
So if my INI file is not at the default path i should move it in to the right path?
Can't i give the direct path if i am not in the default path? -
@victor-wang "Can't i give the direct path if i am not in the default path?" - isn't it what I provided before?
So here it is again:QSettings settings("/PATH_TO_MY_INI_FILE/my_ini_file.ini", QSettings::IniFormat);
Just provide the complete path to the file, that's all.
-
@J.Hilk
http://doc.qt.io/qt-5/qsettings.html#setPathI think i can set the path myself by UserScope.
But It has to be under /home. -
Either you have a hard time understanding what answeres are give to you, or you're messing with us ;-)
So if my INI file is not at the default path i should move it in to the right path?
That's a definite maybe.
Can't i give the direct path if i am not in the default path?
Yes:
@J.Hilk said in [how can i parser the .ini file?](/topic/77013/how-can-i-parser-the-ini-
QSettings settings("c:/Folder1/Folder2/..../my_ini_file.ini", QSettings::IniFormat);
and
@jsulm said in how can i parser the .ini file?:
QSettings settings("/PATH_TO_MY_INI_FILE/my_ini_file.ini", QSettings::IniFormat);
Just provide the complete path to the file, that's all.
-
-
@victor-wang
the;
should not at the end offoreach
statement, or it will do nothing and finish theforeach
statement, just likefor
statement.you should write
qDebug()
notqDebug
, you forget the parentheses. -
@Flotisable
Sorry, i got this :)Besides, i got a question.
Can i only read the key which the value is true? -
@victor-wang
I think you have to write some code to test it, just read the key if it pass the test.