Qt World Summit: Register Today!

QML Serialization

  • I have to serialize whole scene rendered with QDeclarativeView, what's the best approach?
    Do I have to write it from a scratch?

  • Could you go into a bit more detail on what you want to achieve?

  • Sure:

    I have a QML application in which I create 2D boxes (Rectangles) - each box can be opened and contain other boxes and so on - now I need to save the whole box-tree into a file, so I could load and reuse it later.
    I couldn't find anything about serialization in QML - do I have to write own parser in C++ which would read my QML tree or is there any easier way?

  • It is very hard to give sound advice on this, because I have no clue how your app works internally. My first instinct would be to keep track of the state of your rects outside of QML.

  • I think you have to write from scratch. There is a QDataStream class in Qt which helps creating your own binary serialization. I think most basic Qt types support QDataStream. Check out QObject::children() and QDeclarativeView::rootObject. Goot luck, would be nice to hear about your solution.

Log in to reply