vitor13almeida
vitor13almeida

Reputation: 139

Qt Reources - Add and Read JSON file

I need a JSON file to save some info about my app and read it sometimes. And because my app runs in Ubuntu and Windows, I added it to Qt Resources... To access the JSON file I tried:

QFile file(":/files/files/my_settings.json");
qDebug() << "settings file: " << endl << file.readAll();

Upvotes: 1

Views: 1259

Answers (1)

Benjamin T
Benjamin T

Reputation: 8311

First you need to call QFile::open() before calling readAll().

Second point, you can not write to file in Qt Resources.

If you want a cross platform way to save settings and such for your software take a look at QStandardPaths::writableLocation() and QSettings.

Note that QSettings won't handle JSON out of the box, but it will handle all the read/write to file for you (and the file format and location for you if you took car of setting QCoreApplication::applicationName and QCoreApplication::organizationName).

Upvotes: 1

Related Questions