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

  1.  
    #include <QtCore/QCoreApplication>
  2.  
    #include <QSettings>
  3.  
    int main(int argc, char *argv[])
  4.  
    {
  5.  
    QCoreApplication a(argc, argv);
  6.  
    //Qt Use in QSettings Class reading and writing ini file
  7.  
    //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
  8.  
    QSettings *configIniWrite = new QSettings("hahaya.ini", QSettings::IniFormat);
  9.  
    // towards ini Write in the file ,setValue The two arguments to the function are key value pairs
  10.  
    // towards ini The first section of the file writes ,ip The first parameter under section
  11.  
    configIniWrite->setValue("/ip/first", "192.168.0.1");
  12.  
    // towards ini The first section of the file writes ,ip The second parameter under section
  13.  
    configIniWrite->setValue("ip/second", "127.0.0.1");
  14.  
    // towards ini The second section of the file writes ,port The first parameter under section
  15.  
    configIniWrite->setValue("port/open", "2222");
  16.  
    // Delete the pointer when the write is complete
  17.  
    delete configIniWrite;
  18.  
     
  19.  
    return a.exec();
  20.  
    }

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

  1.  
    #include <QtCore/QCoreApplication>
  2.  
    #include <QSettings>
  3.  
    #include <QString>
  4.  
    #include <QDebug>
  5.  
    int main(int argc, char *argv[])
  6.  
    {
  7.  
    QCoreApplication a(argc, argv);
  8.  
     
  9.  
    QSettings *configIniRead = new QSettings("hahaya.ini", QSettings::IniFormat);
  10.  
    // Will read to ini The file is kept in QString in , Take value first , And then through toString() Function to QString type
  11.  
    QString ipResult = configIniRead->value("/ip/second").toString();
  12.  
    QString portResult = configIniRead->value("/port/open").toString();
  13.  
    // Print the results
  14.  
    qDebug() << ipResult;
  15.  
    qDebug() << portResult;
  16.  
    // Delete the pointer when the read is complete
  17.  
    delete configIniRead;
  18.  
    return a.exec();
  19.  
    }

Screenshot of program operation :

from :https://blog.csdn.net/qiurisuixiang/article/details/7760828

Qt Reading and writing ini More articles about the document

  1. 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(& ...

  2. 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 ...

  3. c# Using dynamic libraries DllImport(&quot;kernel32&quot;) 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 ...

  4. 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 ...

  5. C# Reading and writing INI file

    INI Format : [Section1] KeyWord1 = Value1 KeyWord2 = Value2 ... [Section2] KeyWord3 = Value3 KeyWord4 = V ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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] ...

  5. 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 ...

  6. 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 ...

  7. php in &quot;&gt;&gt;&quot; &quot;&lt;&lt;&quot; 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 >>     ...

  8. jmeter Test the performance of the interface that needs to be logged in

    Just one step : https://www.testwo.com/blog/7253

  9. 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 ...

  10. 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< ...