简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM