[Solved] Is it possible to read file from resources files with QSettings?



  • @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QSettings>
    #include <QDebug>
    #include <QResource>

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

    QResource::registerResource("res.rcc");
    QSettings settings1(":/config.ini");
    QString sColor1 = settings1.value("preview").toString();  //File has "success=red", sColor reads to "red"
    QResource::unregisterResource("res.rcc");
    

    qDebug() << sColor1;
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @
    !http://i.imgur.com/XKOBC7o.png()!
    If there no way so what i can use in qt for read file from resources and then parse it by keys like in QSettings?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Might be a silly question but do you also want to save these settings later ? If so you can't do it through Qt's resources system since it's read-only.

    However what is commonly done when you have a default ini file like that is to copy it to the appropriate place the first time the program is started (using QStandardPaths to retrieve that place) and then use it from there.

    Hope it helps



  • Hi, thank you! Seems that problem is in qmake because everyting ok when i launch it.


  • Lifetime Qt Champion

    The file wasn't compiled ?



  • Sorry, i think that i said not clearly. I mean that build or run don't help. I don't know the full sequencing for getting this problem again but qmake solve this. This may be same like with adding QDialog class to project and after getting unresolved linking error until launch qmake.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.