Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i read from .ini file which located in resources files?

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSettings>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QSettings * qsettings = new QSettings(":/config.ini",QSettings::IniFormat);
    bool status = qsettings->value("preview","").toBool();
    qDebug() << status;

}

MainWindow::~MainWindow()
{
    delete ui;
}

http://i.imgur.com/XKOBC7o.png
Once i could do it but now i don't know whats wrong. When i googled this problem i just saw that this impossible but i enshure that i did it before.

like image 330
ratojakuf Avatar asked Mar 18 '23 13:03

ratojakuf


1 Answers

This works like a charm for me:

main.qrc

<!DOCTYPE RCC><RCC version="1.0">
<qresource>
    <file>config.ini</file>
</qresource>
</RCC>

main.cpp

#include <QSettings>
#include <QDebug>

int main()
{
    QSettings settings(":/config.ini", QSettings::IniFormat);
    qDebug() << settings.value("preview", false).toBool();
    qDebug() << settings.value("non-existent", false).toBool();
    return 0;
}

main.pro

TEMPLATE = app
TARGET = main
QT = core
SOURCES += main.cpp
RESOURCES += main.qrc

Build and Run

qmake && make && ./main

Output

true
false
like image 166
lpapp Avatar answered Apr 13 '23 00:04

lpapp