0

I read old topics about QTextDocument serialization: here and here. As I understood, once real method for serialization and deserializtion without additional code is saving and reading documents as html files. But, I think, this method not fast, because html string parsing is a hard and low time operation.

In other case, I can save document in binary format and deserialize them via QTextCursor methods calling in sequence, that faster then html parsing, I think.

Is exist code samples for QTextDocument binary serialization?

Community
  • 1
  • 1
synacker
  • 1,722
  • 13
  • 32
  • possible duplicate? http://stackoverflow.com/questions/3254669/how-to-implement-qtextdocument-serialization – Arun Aug 12 '15 at 07:32
  • @Arun I wrote this link in my post. There exist descsription that serialization to binary format possible, but without code samples. – synacker Aug 12 '15 at 07:36
  • @Milovidov - it will be VERY hard to do binary serialization, it is not like it is a single byte array, internally the text document has a number of different resources, and they are not even accessible through the public API. Have you actually establish that you have a performance problem empirically? – dtech Aug 12 '15 at 07:46
  • 1
    @ddriver I don't have benchmarks because I don't know whith which solution I can compare. The binary serialization faster then text string parsing by logic. – synacker Aug 12 '15 at 08:13
  • @Milovidov - there is no doubt that parsing formatted text will be slower, but you haven't established that it is TOO SLOW to be useful. Binary serialization, as I said, in this case is close to practically impossible. So you might want to go with HTML, and ONLY if it proves to be TOO SLOW, bother yourself with a far more complex solution, too complex to be worth the performance gain. – dtech Aug 12 '15 at 08:16
  • @ddriver of course, I understand this. I just seraching in existing solutions with binary serializations. For example, may be exist Qt text editor that saving and load files in own binary format. – synacker Aug 12 '15 at 08:19

2 Answers2

0

There is QTextDocumentWriter, but there is no respective reader. Check this answer if you need read document.

Community
  • 1
  • 1
Marek R
  • 32,568
  • 6
  • 55
  • 140
  • `QTextDocumentWriter` has exactly the problem the OP describes. It will extra format to either HTML or ODF, or destroy the extra information and output a plain text file. – dtech Aug 12 '15 at 08:05
0

I didn't found a pure binary seraialization, but I found working sample for reading ODF format files to QTextDocument. This also string (xml) parsing method, but odf format accept avoid storaging several files for document, if him contains images.

Source code can be viewed in okular git repo here

synacker
  • 1,722
  • 13
  • 32