Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read .odt file and loop over characters
QtWS25 Last Chance

Read .odt file and loop over characters

Scheduled Pinned Locked Moved Unsolved General and Desktop
odthtmlfileqtextdocument
6 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tamfub
    wrote on 22 Sept 2020, 11:01 last edited by Tamfub
    #1

    Hello everybody.

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Sept 2020, 19:03 last edited by
      #2

      Hi,

      For loading .odt files, you might want to check the Calligra project.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • A Offline
        A Offline
        artwaw
        wrote on 22 Sept 2020, 19:51 last edited by
        #3

        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.

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        1
        • T Offline
          T Offline
          Tamfub
          wrote on 23 Sept 2020, 07:42 last edited by Tamfub
          #4

          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:

          QJsonObject({"character":"H","font":50,...});
          

          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?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            artwaw
            wrote on 23 Sept 2020, 09:58 last edited by
            #5

            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.

            For more information please re-read.

            Kind Regards,
            Artur

            T 1 Reply Last reply 23 Sept 2020, 14:44
            2
            • A artwaw
              23 Sept 2020, 09:58

              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.

              T Offline
              T Offline
              Tamfub
              wrote on 23 Sept 2020, 14:44 last edited by
              #6

              @artwaw Yes, it works fine eventually :)

              1 Reply Last reply
              0

              1/6

              22 Sept 2020, 11:01

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved