One background
1 ini The file is introduced
.ini File is Initialization File Abbreviation , Initialization file .
except windows Now many applications under other operating systems also have .ini file , It is used to configure application software to meet the requirements of different users . You don't have to edit these directly .ini file , The graphical interface of the application program can be operated to achieve the same function . It can be used to store software information , Registration information, etc .
2 ini File format
INI Document by section 、 key 、 The value of .
section
[section]
Parameters ( key = value )
name=value
Here's a ini Examples of documents
[Section1 Name]
KeyName1=value1
KeyName2=value2
...
[Section2 Name]
KeyName21=value21
KeyName22=value22
among :[Section1 Name] Used to represent a paragraph . because INI The file may be shared in the project , So use [Section Name] Section name to distinguish parameter areas for different purposes . for example :[Section1 Name] Indicates the sensitivity parameter area of the sensor ;[Section2 Name] Indicates the measurement channel parameter area, etc .
annotation : Use a semicolon to indicate (;). The text after the semicolon , It's all annotations until the end of the line .
Two Qt Write ini file
-
#include <QtCore/QCoreApplication>
-
#include <QSettings>
-
int main(int argc, char *argv[])
-
{
-
QCoreApplication a(argc, argv);
-
//Qt Use in QSettings Class reading and writing ini file
-
//QSettings The first argument to the constructor is ini Path to file , The second parameter is for ini file , The third parameter can default to
-
QSettings *configIniWrite = new QSettings("hahaya.ini", QSettings::IniFormat);
-
// towards ini Write in the file ,setValue The two arguments to the function are key value pairs
-
// towards ini The first section of the file writes ,ip The first parameter under section
-
configIniWrite->setValue("/ip/first", "192.168.0.1");
-
// towards ini The first section of the file writes ,ip The second parameter under section
-
configIniWrite->setValue("ip/second", "127.0.0.1");
-
// towards ini The second section of the file writes ,port The first parameter under section
-
configIniWrite->setValue("port/open", "2222");
-
// Delete the pointer when the write is complete
-
delete configIniWrite;
-
-
return a.exec();
-
}
After running the program , Open the program directory hahaya.ini file , The results are shown in the following figure :
3、 ... and Qt read ini file
-
#include <QtCore/QCoreApplication>
-
#include <QSettings>
-
#include <QString>
-
#include <QDebug>
-
int main(int argc, char *argv[])
-
{
-
QCoreApplication a(argc, argv);
-
-
QSettings *configIniRead = new QSettings("hahaya.ini", QSettings::IniFormat);
-
// Will read to ini The file is kept in QString in , Take value first , And then through toString() Function to QString type
-
QString ipResult = configIniRead->value("/ip/second").toString();
-
QString portResult = configIniRead->value("/port/open").toString();
-
// Print the results
-
qDebug() << ipResult;
-
qDebug() << portResult;
-
// Delete the pointer when the read is complete
-
delete configIniRead;
-
return a.exec();
-
}
Screenshot of program operation :
from :https://blog.csdn.net/qiurisuixiang/article/details/7760828
Qt Reading and writing ini More articles about the document
- Qt Yes ini Reading and writing of documents
We studied the following Qt Next ini Reading and writing of documents , Don't bullshit , On dry . write in ini file WriteIni.cpp void WriteIni::writeSettings() { QSettings settings(& ...
- QT Reading and writing ini The configuration file
/******** Here's how to write ini file *************************/ //Qt Use in QSettings Class reading and writing ini file //QSettings The first of constructors ...
- c# Using dynamic libraries DllImport("kernel32") Reading and writing ini file ( Provide Dmo download )
c# Using dynamic libraries DllImport("kernel32") Reading and writing ini file Since I read design patterns , It really changes a programmer's habits . I think , Experience can also be seen in one's habits , Look at his code ...
- VB Reading and writing INI File four functions and related API Detailed instructions
WritePrivateProfileString Function description source :http://blog.csdn.net/wjb9921/article/details/2005000 In the program we wrote , There's always one ...
- C# Reading and writing INI file
INI Format : [Section1] KeyWord1 = Value1 KeyWord2 = Value2 ... [Section2] KeyWord3 = Value3 KeyWord4 = V ...
- WIN32 Reading and writing INI Document method
In the program, it is often used to set or save a small amount of data , So that the program can be used in the next execution , For example, save the position of the window when the program is executed . size . Some users set up Data and so on , stay Dos When programming , We usually produce one of our own ...
- Reading and writing ini file
C# Use file streams to read and write ini file background Before using ini File as the configuration file of the program , I think the structure is simple and clear , It's easy to configure . Then the operation mode is through the WindowsAPI, And then find one online based on WindowsAPI ...
- stay WinCe Platform reading and writing ini file
In the last article, we developed windows mobile Today's plug-in on , I find wince Not supported on the platform, for example GetPrivateProfileString And so on API function . I didn't find anything that satisfied me on the Internet ...
- Windows Intermediate reading and writing ini file
.ini File is Initialization File Abbreviation , Initialization file , yes windows The storage format of the system configuration file of , To configure the application software to meet the requirements of different users . There are many kinds of configuration files, such as ini The configuration file ,XML ...
Random recommendation
- Pycharm5 Registration method
0x1 , install 0x2 , Adjust the time to 2038 year . 0x3 , apply 30 Try it out for days 0x4, sign out pycharm 0x5, Time to adjust back . ## Registration method 2### Registration method : stay Choose... When registering Licen ...
- MongoDB file 、 aggregate 、 Database introduction
file summary The document is MongoDB Core concept of , It's the basic unit of data , Very similar to rows in a relational database . stay MongoDB in , The document is represented as an ordered set of key value pairs .MongoDB Use Javascript shell, Table of documents ...
- java Programming skills
Welcome to make suggestions, point out mistakes and communicate with each other . 1. Count the number of objects , For example, how many bullets were fired . public class Bullet { public static int count = 0; public B ...
- bzoj2259
That's a good question , First of all, the way of reading has a sense of jumping : Read in Si after , We can jump straight back Si, You can think of the shortest path , Let the sequence be a[], We set up n+1 It's the end if i+a[i]<=n+1 that i-->i+a[i] ...
- webservice05#soap news
1, SOAPMessage chart 2, SOAP Message creation 1> The first one is simple WebService service package com.yangw.soap.service; import jav ...
- DevExpress VCL Controls 2019 Development roadmap (No.3)
[DevExpress VCL Controls download ] ExpressFlowChart Allow end users to modify shapes (v19.1) Allow developers to XML Format definition custom shapes (v19.1) Use 30 Multiple new shapes ...
- php in ">>" "<<" The meaning of
Operator explain <<< The Conduit , Introduced from c++. Treat what is enclosed by a tag as a string , The variables are expanded << Move left , Bit operators >> ...
- jmeter Test the performance of the interface that needs to be logged in
Just one step : https://www.testwo.com/blog/7253
- hadoop Learning notes - Catalog
Here are hadoop The order of learning notes : hadoop Learning notes ( One ): Concept and composition hadoop Learning notes ( Two ):centos7 Three node installation hadoop2.7.0 hadoop Learning notes ( 3、 ... and ):hdfs Architecture and reading ...
- hdu 4417 In the interval h Small number Divide trees
Dichotomous search the nearest one than h Small number #include<cstdio> #include<iostream> #include<algorithm> #include< ...