adontz
adontz

Reputation: 1438

QML map binding

I'm complete noob in Qt, so my question may sound too stupid, but I really need help. I know C++ a little and that's it.

So, my task is to write a C++ program which reads INI-alike file (I can do this, but not sure of most correct/Qt way)

height=20
width=15

or

height=int:20
width=int:15

if properties should be strongly typed. File format is not very important. To make it clear, I have no idea what properties will be defined in this file, names or types are unknown to me at compile time.

after that program loads QML file (I can do this) and injects loaded file data (have no idea how to do this) as JavaScript object, for instance named "Settings", so that QML property bindings will use it like

Rectangle {
   width: Settings.width
}

So the questions are:

  1. What is most correct/qt-style way to read INI-alike file?
  2. How can I inject read data as JavaScript object into QML so that QML property binding will use it?

Upvotes: 1

Views: 599

Answers (1)

Jablonski
Jablonski

Reputation: 18524

First: The most Qt-style way is using QSettings class:

QSettings *settings = new QSettings("G:/options1.ini",QSettings::IniFormat);

qDebug()<< "height" <<settings->value("height").toInt();
qDebug()<< "width" <<settings->value("width").toInt();

My file:

height=20
width=15

Output:

height 20 
width 15 

See description of this class. It is really helpful thing.

http://qt-project.org/doc/qt-4.8/qsettings.html

Upvotes: 1

Related Questions