Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize QT imitating MFC to read INI File

Shulou Source: shulou.com Published: 2022-06-02 06:39:25 10月02日 Update

This article mainly explains the "QT imitates MFC to read INI files how to achieve", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "QT imitating MFC to read INI files how to achieve" it!

QT imitates MFC to read INI files (Chinese is supported)

# include

# include

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

}

Thank you for your reading, the above is the content of "QT imitates MFC to read INI file". After the study of this article, I believe you have a deeper understanding of how QT imitates MFC to read INI file, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Documents learning content that is ideas situations articles more knowledge knowledge points articles follow questions Chinese practice push support research verification Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei Shulou Technology Redmi OPPO Reno