QT仿照MFC读取INI文件(支持中文)

QT仿照MFC读取INI文件(支持中文)



#include <QSettings> 
#include <QtGui> 
UINT SEGetPrivateProfileInt(LPCSTR lpAppName, LPCSTR lpKeyName,  
    INT nDefault, LPCSTR lpFileName) 

    UINT nReturn = nDefault; 
    QString strDefault, strItem, strSection, strKey; 
    strItem = ""; 
    strDefault.sprintf("%d", nDefault); 
 
    QTextCodec *codec = QTextCodec::codecForName("GB2312"); 
    QSettings Setting(lpFileName, QSettings::IniFormat);     
    Setting.setIniCodec(codec);     
    strSection = QString::fromLatin1(lpAppName, strlen(lpAppName)); 
    strKey = QString::fromLatin1(lpKeyName, strlen(lpKeyName)); 
    strItem.append(strSection); 
    strItem.append("/"); 
    strItem.append(strKey); 
     nReturn = Setting.value(strItem, strDefault).toUInt(); 
    return nReturn; 

 
DWORD SEGetPrivateProfileString(LPCSTR lpAppName, LPCSTR lpKeyName,   
    LPCSTR lpDefault, LPSTR lpReturnedString, DWORD nSize, LPCSTR lpFileName) 

    DWORD dwLen = 0; 
    QString strReturn; 
    QString strDefault, strItem, strSection, strKey; 
    strItem = ""; 
    strDefault = lpReturnedString; 
 
    QTextCodec *codec = QTextCodec::codecForName("GB2312"); 
    QSettings Setting(lpFileName, QSettings::IniFormat);     
    Setting.setIniCodec(codec);     
    strSection = QString::fromLatin1(lpAppName, strlen(lpAppName)); 
    strKey = QString::fromLatin1(lpKeyName, strlen(lpKeyName)); 
    strItem.append(strSection); 
    strItem.append("/"); 
    strItem.append(strKey); 
     strReturn = Setting.value(strItem, strDefault).toString(); 
 
    QByteArray ba = strReturn.toAscii(); 
    char *lpszData = ba.data(); 
    dwLen = strlen(lpszData); 
    dwLen = dwLen > nSize ? nSize : dwLen; 
    strncpy(lpReturnedString, lpszData, dwLen); 
    return dwLen; 
}

时间: 2024-08-08 01:13:15

QT仿照MFC读取INI文件(支持中文)的相关文章

C#读取ini文件的方法

最近项目用到ini文件,读取ini文件,方法如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.Specialized; using System.IO; using System.Runtime.InteropServices; using System.Windows.Forms; namespace test{ /

bat 读取 ini 文件

bat 读取 ini 文件 参考链接:https://stackoverflow.com/questions/2866117/windows-batch-script-to-read-an-ini-file 这个 bat 支持 ini 的键值与=号之间存在空格,例如 key1 = value1 readini.bat: @if (@[email protected]) @end /* -- batch / JScript hybrid line to begin JScript comment

helm-mode打开文件支持中文搜索

.title { text-align: center; margin-bottom: .2em } .subtitle { text-align: center; font-size: medium; font-weight: bold; margin-top: 0 } .todo { font-family: monospace; color: red } .done { font-family: monospace; color: green } .priority { font-fami

Linux下读取Ini文件类

Linux下读取Ini文件类 最近项目上有需要读取Ini文件 所谓Ini文件也就是文本文档 并且以 //注释1 /*注释2 [Section] Key1=aaa Key2=bbb 这种形式存在的文档 自己编写了一个类  比较使用 简单 可以跨平台读写INI文件 头文件Ini.h #include <map> #include <string> using namespace std; #define CONFIGLEN 256 enum INI_RES { INI_SUCCESS,

读取INI文件 - Delphi篇

程序经常需要读取一些用户设定值,怎么完成这个过程? B/S程序一般使用XML文件,而C/S程序则使用INI文件. 前篇<C#迁移之callXBFLibrary - 2(调用非托管DLL)>是C#读取INI的示例. 本篇介绍使用Delphi完成这个过程. 首先,引用单元. uses Windows, SysUtils, Classes, DB, ADODB, StrUtils, Forms, IniFiles; 其中"IniFiles"即是我们要引用的单元. 然后,定义类变量

Python 中读取csv文件中有中文的情况

Python 中读取csv文件中有中文的情况,提示编码问题: 读取的时候: import sys reload(sys) #中文错误 sys.setdefaultencoding( "utf-8" ) save 存储的时候: dataframe可以使用to_csv方法方便地导出到csv文件中,如果数据中含有中文,一般encoding指定为"utf-8″,否则导出时程序会因为不能识别相应的字符串而抛出异常,index指定为False表示不用导出dataframe的index数据

springBoot使用@Value标签读取*.properties文件的中文乱码问题

上次我碰到获取properties文件中的中文出现乱码问题. 查了下资料,原来properties默认的字符编码格式为asci码,所以我们要对字符编码进行转换成UTF-8格式 原先代码:@PropertySource("classpath:fu.properties") 改后代码:@PropertySource(value="classpath:fu.properties",encoding="utf-8") 然后就不会出现@Value标签读取*

利用GetPrivateProfileString读取ini文件的字段

//INIClass读取类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.IO; using UnityEngine; namespace cReadConfigFile { public class INIClass { public string inipath; [

C++ 读取INI文件

Windows操作系统专门为此提供了6个API函数来对配置设置文件进行读.写: GetPrivateProfileInt() 从私有初始化文件获取整型数值GetPrivateProfileString() 从私有初始化文件获取字符串型值GetProfileInt 从win.ini 获取整数值GetProfileString 从win.ini 获取字符串值WritePrivateProfileString 写字符串到私有初始化文件WriteProfileString 写字符串到win.ini 我们