QDataStream is a low level mechanism. You want a high level one thus you have to use this low level mechanism to implement a high level mechanism. Simply speaking, if you want to detect what is the type of data in the stream, stream additional data that will let you detect the type. You can stream the name of the type, for example.
Qt Code:To copy to clipboard, switch view to plain text mode
You can use QMetaType to have automatic coversion of the type id to the name of the type to avoid unnecessary comparisons like in my code above.
I'm not sure how templates would be helpful here. QVariant is a class on its own, you don't create a new "QVariant" class in each application that uses Q_DECLARE_METATYPE.BTW, I realize that QVariant (on its own) can't recreate every possible structure in the world, but through template-programming was thinking it should be able reconstruct any type (from the type identifier in the header).
The only relevant docs are in QDataStream reference. This is really a marginal topic in Qt.The documentation (that I've come across) is limited on serialization. Do you have anything you'd recommend? Seems like it would be a great tutorial (maybe it is).






Reply With Quote

I read too much into the serialization support.
Bookmarks