QT仿照MFC读取INI文件怎么实现(mfc,qt,开发技术)

时间:2024-05-05 12:10:28 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

    QT%E4%BB%BF%E7%85%A7MFC%E8%AF%BB%E5%8F%96INI%E6%96%87%E4%BB%B6%E6%80%8E%E4%B9%88%E5%AE%9E%E7%8E%B0

#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;
}

本文:QT仿照MFC读取INI文件怎么实现的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:QT多线程类数组同时开启几十个线程怎么实现下一篇:

7 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18