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

走远了吗. 提交于 2019-12-05 13:45:37

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!