Unsolved Read .odt file and loop over characters
In my previous topic, I managed to write a .odt file starting from a list of Symbols (Symbol is a class defined by me).
Now, I would like to:
open a .odt file and read its content
loop over the characters to retrieve their style attributes and build a list of Symbols.
Is there a way to do it? Can it be done with .html files as well?
I am up for any clarification, if needed.
SGaist Lifetime Qt Champion last edited by
For loading .odt files, you might want to check the Calligra project.
artwaw last edited by
I believe @Tamfub - you should revise your document saving part. It easier to load into QTextDocument html file, so you could internally save/load as html, then eventually export upon save (or every significant change) to odt for users to download ready file.
You load it as QString from the file, then use the setter method. Simple as that, QString should load with all the markup.
Once you use the setter method of QTextDocument no further steps needed.
Hi @SGaist and @artwaw, thanks for your precious suggestions!
Before you could reply, I thought of another solution, that is saving a .dat file instead of a .odt/.html one.
The server receives packets from multiple clients via QTcpSockets. The client:
creates a Symbol object and stores it in a collection:
/* 'h': character 50: font weight ...: other style attributes */ Symbol s('h', 50, ...);
fills a QJsonObject with the attributes of the just created Symbol:
QByteArray info=""; QJsonObject qjo; qjo.insert("character", (QString)s.getCharacter()); qjo.insert("fontsize", s.getFontWeight()); ... QJsonDocument doc(qjo); QString strJson(doc.toJson(QJsonDocument::Compact)); info.append(strJson);
writes the QByteArray on the socket:
Connection *con = Connection::getInstance(); con->getSocket()->write(info);
The server receives a QJsonObject:
So my idea is to write this QJsonObject on a .dat file (for each character received on the server). Actually, I don't need to store intelligible files, since the server opens them and sends these lines back to the client, who will deserialize them and rebuild the Symbols.
What do you think about this?
artwaw last edited by
Whatever rows your boat, really. I have not seen any documentation of your project, nor am I part of it. If it works for you it works for you :)
Previously you asked about storing rich document in odt file (and consequently reading from it), made from custom source of data. Now you simply jettisoned whole idea - if that works for you then again, it works for you.
@artwaw Yes, it works fine eventually :)