QSettings *settings = new QSettings("settings.cfg",QSettings::NativeFormat); settings->setValue(sector + "/" + key,value); //!< устанавливаем значение settings->sync(); //!< записываем настройки
QSettings *settings2 = new QSettings("settings.cfg",QSettings::NativeFormat); value = settings2->value(sector + "/" + key,default_value).toString(); //!< выводим на экран настройки из файла, если там ничего нет то default_value
C++ (Qt)QSettings settings("settings.cfg",QSettings::NativeFormat);settings.value("mykey");
C++ (Qt)#include <QSettings>#include <QDebug>QMap <QString,QString> myByf; void setSettingsCore(QString sector, QString key, QString value, QString firstName){ QSettings *settings = new QSettings(firstName+".cfg",QSettings::NativeFormat); settings->setValue(sector + "/" + key,value); settings->sync(); } QString getSettingsCore(QString sector, QString key, QString firstName, QString defaultValue){ QSettings *settings2 = new QSettings(firstName+".cfg",QSettings::NativeFormat); return settings2->value(sector + "/" + key,defaultValue).toString();} QString getMap(QString key){ return myByf.value(key);} void setMap(QString key,QString value){ myByf.insert(key,value);} void BkdmSettings::setSettings(QString sector, QString key, QString value, QString firstName){ setMap(key,value); setSettingsCore(sector, key, value, firstName);} QString BkdmSettings::getSettings(QString sector, QString key, QString defaultValue, QString firstName){ if (getMap(key)=="") { if (getSettingsCore(sector, key, firstName,"")=="") { qDebug()<<"ERR"; return ""; } else return(getSettingsCore(sector, key, firstName,defaultValue)); } else return getMap(key);}
C++ (Qt)void setSettingsCore(QString sector, QString key, QString value, QString firstName){ QSettings *settings = new QSettings(firstName+".cfg",QSettings::NativeFormat); settings->setValue(sector + "/" + key,value); settings->sync(); } QString getSettingsCore(QString sector, QString key, QString firstName, QString defaultValue){ QSettings *settings2 = new QSettings(firstName+".cfg",QSettings::NativeFormat); return settings2->value(sector + "/" + key,defaultValue).toString();}
C++ (Qt)void setSettingsCore(QString sector, QString key, QString value, QString firstName){ QSettings *settings = new QSettings(firstName+".cfg",QSettings::NativeFormat); settings->setValue(sector + "/" + key,value); settings->sync(); delete settings; //! clearing memory}QString getSettingsCore(QString sector, QString key, QString firstName, QString defaultValue){ QSettings *settings2 = new QSettings(firstName+".cfg",QSettings::NativeFormat); QString resStr = settings2->value(sector + "/" + key,defaultValue).toString(); delete settings2; //! clearing memory return resStr;}
C++ (Qt)void setSettingsCore(QString sector, QString key, QString value, QString firstName){ QSettings settings(firstName+".cfg",QSettings::NativeFormat); settings.setValue(sector + "/" + key,value); settings.sync(); }QString getSettingsCore(QString sector, QString key, QString firstName, QString defaultValue){ QSettings settings2(firstName+".cfg",QSettings::NativeFormat); return settings2.value(sector + "/" + key,defaultValue).toString();}