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. Merge QTextDocument
Forum Updated to NodeBB v4.3 + New Features

Merge QTextDocument

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by VRonin
    #1

    It will probably be trivial and I just can't find it but is it possible to append a QTextDocument to another?

    I thought I could use for (int blockIter = 0; blockIter< tempDocument.blockCount(); ++blockIter) but there is no insertion method either in QTextDocument or in QTextCursor that accepts QTextBlock

    Thanks in advance

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    kshegunovK 1 Reply Last reply
    0
    • VRoninV VRonin

      It will probably be trivial and I just can't find it but is it possible to append a QTextDocument to another?

      I thought I could use for (int blockIter = 0; blockIter< tempDocument.blockCount(); ++blockIter) but there is no insertion method either in QTextDocument or in QTextCursor that accepts QTextBlock

      Thanks in advance

      kshegunovK Away
      kshegunovK Away
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @VRonin
      Hi,
      Probably the easiest way is to attach a cursor to the document and insert additional data with QTextCursor::insertHtml. Something along the lines of:

      QTextDocument document1, document2;
      
      QTextCursor cursor(document1);
      cursor.insertHtml(document2.toHtml());
      // ...
      

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        Yes, that's what I ended up doing, but since my document contains resources I needed to handle them separately and it was a nightmare.
        Digging around it looks like my problem and Bug #9258 are two sides of the same coin

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        kshegunovK 1 Reply Last reply
        0
        • VRoninV VRonin

          Yes, that's what I ended up doing, but since my document contains resources I needed to handle them separately and it was a nightmare.
          Digging around it looks like my problem and Bug #9258 are two sides of the same coin

          kshegunovK Away
          kshegunovK Away
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @VRonin
          To be frank the QTextDocument class (and friends) could use a good rewrite, but I doubt anyone is interested in that. I'm glad you solved your issue, though.

          Cheers!

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            Just to solve the issue, even if it's not pretty it works
            To append QTextDocument A to QTextDocument B:

            • every time you add a resource to A you need to keep track of name and type manually
            • add those resources to B making sure you do not run into naming conflict and, if you change a name to a resouce you should amend it's reference in the html code of A
            • add the adjusted htm from A to B using the QTextCursor interface

            @kshegunov said:

            To be frank the QTextDocument class (and friends) could use a good rewrite

            Yes they feel really messy

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            1

            • Login

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