Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize QT imitating MFC to read INI File

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report