how can i parser the .ini file?
-
Hi, i'm using qt5.5 on my computer.
I am trying to parse a .ini file.
But i do not know how to do it.This is my .ini file here
Please help!
-
Hi, i'm using qt5.5 on my computer.
I am trying to parse a .ini file.
But i do not know how to do it.This is my .ini file here
Please help!
@victor-wang
How about QTextStream::readLine() and QString::split()? -
@victor-wang
How about QTextStream::readLine() and QString::split()?@Flotisable
Actually i need it to help me get the group automatically.
I know Qt can do it but i do not know how to do it. -
@Flotisable
Actually i need it to help me get the group automatically.
I know Qt can do it but i do not know how to do it.@victor-wang What about QSettings? http://doc.qt.io/qt-5/qsettings.html
-
@Flotisable
Actually i need it to help me get the group automatically.
I know Qt can do it but i do not know how to do it.@victor-wang Use http://doc.qt.io/qt-5/qsettings.html#QSettings-2 and pass QSettings::IniFormat as first parameter.
-
@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. -
@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();
-
@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?
-
@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);
-
@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? -
@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.
-
@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?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);
-
@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);
This post is deleted! -
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);
@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
-
@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
-
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? -
@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.
-
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
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. -
@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.
-
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.