4
#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.

László Papp
  • 51,870
  • 39
  • 111
  • 135
ratojakuf
  • 708
  • 1
  • 11
  • 21
  • `When i googled this problem i just saw that this impossible`-> why don't you put the link into this question? I do not understand you. Now we have to do exactly the same that you already did. That is annoying. – László Papp Dec 21 '14 at 01:11
  • @lpapp, i just found one not more and that's why asked here because i don't think that this is true and also oi said that i did this before. http://developer.nokia.com/community/discussion/showthread.php/217003-Ini-in-Qrc?p=808805&viewfull=1#post808805 – ratojakuf Dec 21 '14 at 01:34
  • @lpapp, Is there another solutions with store file in resource file and parse by key like QSettings do it? I am interested in Qt varint of solving this problem, if it exists, of course. – ratojakuf Dec 21 '14 at 04:48
  • Have you tried my example below? Just copy/paste and run it. – László Papp Dec 21 '14 at 16:45

1 Answers1

7

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
László Papp
  • 51,870
  • 39
  • 111
  • 135
  • Omg! Thank you. When i looked at your same code and the fact that he work's i try to do same and everything ok after i launch qmake. So Qt creator don't include resource file until launch qmake? – ratojakuf Dec 21 '14 at 17:22
  • 2
    @9vashrotebal: if you change the qmake files (.pr{i,o,f}), qmake is better rerun, yeah. – László Papp Dec 21 '14 at 17:24