Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Is it possible to read file from resources files with QSettings?
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kavesebop
    wrote on last edited by
    #1

    @#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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kavesebop
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The file wasn't compiled ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kavesebop
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved