Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QSettings - reading INI file

I create an INI file and then try to read it. There is no compile errors and the file is there but I'm not receiving any data in my QStringList

QFile checkConfig(configPath);
    if(checkConfig.exists())
    {
        QSettings* settings = new QSettings(configPath, QSettings::IniFormat);
        settings->beginGroup("General");
        const QStringList childKeys = settings->childKeys();
        QStringList values;
        foreach (const QString &childKey, childKeys)
            values << settings->value(childKey).toString();
        settings->endGroup();
        QString test = configPath;
        int a;
    }

this is my INI file

[General]
InterviewPath=C:/1234
like image 953
rreeves Avatar asked Dec 26 '22 05:12

rreeves


2 Answers

Problem stemmed from the INI not being created correctly.

QSettings settings(configPath, QSettings::IniFormat);
    settings.beginGroup("/General");
    settings.setValue("/InterviewPath", interviewPath);
    settings.endGroup();
like image 109
rreeves Avatar answered Dec 29 '22 05:12

rreeves


Do not use settings->beginGroup("General");

        QCoreApplication a(argc, argv);
    QSettings* settings = new QSettings("d:/a.ini", QSettings::IniFormat);
  //  settings->beginGroup("General");
    const QStringList childKeys = settings->childKeys();
    QStringList values;
    foreach (const QString &childKey, childKeys)
        values << settings->value(childKey).toString();
   // settings->endGroup();
    qDebug()<<values;
like image 24
Aliceljm Avatar answered Dec 29 '22 06:12

Aliceljm