Seek advice on how to store data structure of qml
-
Dear all, I seek your advice on data structure of qml. We are implementing a powerpoint-like application using qml.
For each slide, we can add objects such as pictures, texts, videos, etc. How do we store these content of each slide? I think the main problem is the content to be stored is unstructured, as a alide can contain different number of objects.Any suggestion?
Thank you for your help.
-
Hi franziss, i think the basic and helpful way to store the data is, using xml. And, you can have a look at the "QML presentation system":http://labs.qt.nokia.com/2011/05/30/a-qml-presentation-system/#comment-22367 here :)
-
JSON might be easier than XML for data storage. QML can load JSON into javascript objects quite easily, and you can manipulate it from there. If you use XML, you'll probably need to import a XML->JSON JS library.
But you can always just store the content in QML, especially if you want create a QML object for each 'data object'. At its core, QML is just a language for creating a hierarchy of objects with property initializations (and bindings).
-
I would be very interested in seeing a video of your powerpoint clone once it is ready. Qt Quick is a new technology with users still testing the limits and developers removing obstacles in the way. To me it looks like you are about to go boldly where no man has gone before.
I have seen only one thing which tries to achieve this:
http://doc.qt.nokia.com/4.7/declarative-toys-dynamicscene.html -
@aalpert: Yes, JSON is more easier and smaller for data storage, but how about a well-designed XmlListModel, and for cases that we want munipulate the data in Qt C++ ? If there is a way can make us munipulate the data in both QML(or js) and Qt C++ using JSON ? I remember Qt C++ doesn't has a JSON parsing API itself.
Br,
-
Thank you guys for your advices and suggestions.
@Chuck.Gao: XmlListModel is good if multiple devices need to communicate with each other, and data can be transferred between each device via xml. According to this example http://doc.qt.nokia.com/4.7-snapshot/qml-xmllistmodel.html#details, it seems that the data must be structured. We can assume that each <item> is a slide, but the objects in the slide are unstructured, that is, we can have as many number and different types of objects in the slide. So can xml handle unstructured data or a qml data?
@aaplert: can JSON handle unstructured data? Your suggestion on directly using qml is interesting. Is it possible that I create a qml file for each slide, which defines the slide and its objects. So when I load the slide, I will read from its corresponding qml file. And when I amend the slide, I will write to the corresponding qml file? Or I will need to use c++ as the middle man between Qt and the qml file?
-
You can use QtScript to parse JSON from C++, or do it in QML and pass the JS object into C++.
@franziss JSON and XML can handle unstructured data as 'lists of objects', much like the QML default property. While there is no built in facility to write QML files from C++ due to the difficulty of a complete system, in the simple case it should be very easy to iterate through the generated objects and print out property values through object-introspection (this would not preserve any bindings). This would have to be done in C++ though - if only because QML by default does not have file writing capabilities.
-
Hi aaplert,
Ok, thank you, I get it now, xml can handle unstructured data as follows:
@
<?xml version="1.0" encoding="utf-8"?>
<slide>
<object>
...... more details
</object>
<object>
...... more details
</object>
</slide>
<slide>
<object>
...... more details
</object>
<object>
...... more details
</object>
</slide>
@