QSettings *ConfigIni = new QSettings(QSettings::Ini);
ConfigIni->insertSearchPath(QSettings::Unix, "/home/Dawei");.//配置文件目录
ConfigIni->writeEntry(QString::fromUtf8("/config./opt/参数1"), QString::fromUtf8("中文"));
String aaa = ConfigIni->readEntry(QString::fromUtf8("/config./opt/参数1");
delete ConfigIni;
会在/home/Dawei目录下生成config.rc配置文件内容为
[opt]
参数1=中文
---------------------------------------
QSettings settings("../etc/bpms.conf", QSettings::IniFormat, &app);
QString db_hostname = settings.value("hostname").toString();
QString db_database = settings.value("database").toString();
QString db_username = settings.value("username").toString();
QString db_password = settings.value("password").toString();
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName(db_hostname);
db.setDatabaseName(db_database);
db.setUserName(db_username);
db.setPassword(db_password);
---------------------------------------------------------------
需要#include
只举几个简单的例子:
1、用QSettings写注册表
QSetti