Results 1 to 4 of 4

Thread: How to combine multiple .html files together into one .html

  1. #1
    Join Date
    Jul 2008
    Location
    Munich
    Posts
    73
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question How to combine multiple .html files together into one .html

    I am using QTextEdit for this. Method insertHtml() helped. But this method works not as I imagine.

    My file1.html is
    Qt Code:
    1. <html>
    2. <body>
    3. <p>
    4. <h2>title1</h2>
    5.  
    6. <ul>
    7. <li>bla</li>
    8. <li>bla</li>
    9. </ul>
    10. </p>
    11. <br>
    12. </body>
    13. </html>
    To copy to clipboard, switch view to plain text mode 

    File2.html is
    Qt Code:
    1. <html>
    2. <body>
    3. <p>
    4. <h2>title2</h2>
    5.  
    6. <ul>
    7. <li>blabla</li>
    8. <li>blabla</li>
    9. </ul>
    10. </p>
    11. <br>
    12. </body>
    13. </html>
    To copy to clipboard, switch view to plain text mode 

    My code is:
    Qt Code:
    1. QString fileName1(":/file1.html");
    2. QFile file1(fileName1);
    3. if (file1.open(QIODevice::ReadOnly))
    4. {
    5. QString data1(file1.readAll());
    6. if (fileName1.endsWith(".html"))
    7. textEdit->insertHtml(data1);
    8. }
    9.  
    10. QString fileName2(":/file2.html");
    11. QFile file2(fileName2);
    12. if (file2.open(QIODevice::ReadOnly))
    13. {
    14. QString data2(file2.readAll());
    15. if (fileName2.endsWith(".html"))
    16. textEdit->insertHtml(data2);
    17. }
    To copy to clipboard, switch view to plain text mode 

    The problem is, the title of the file2 is always followed by the last bla, not aligned to the left of the file. If I insert a break line between these two parts:
    Qt Code:
    1. textEdit->insertHtml("<hr>");
    To copy to clipboard, switch view to plain text mode 
    The line is beneath the file2's title. crazy!

    Anyone can help? Or is there another way to complish this function?
    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to combine multiple .html files together into one .html

    You probably should only insert a fragment, hot a whole HTML document including the html tags. Use QRexExp to filter out the contents of the body tag.

  3. #3
    Join Date
    Jul 2008
    Location
    Munich
    Posts
    73
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to combine multiple .html files together into one .html

    It doesn't work. I tried:
    Qt Code:
    1. QString test1 = "<h2>v2.6.3</h2>";
    2. QString test2 = "<h2>v2.7.0</h2>";
    3.  
    4. textEdit->insertHtml(test1);
    5. textEdit->insertHtml("<hr>");
    6. textEdit->insertHtml(test2);
    To copy to clipboard, switch view to plain text mode 

    The output is:
    Qt Code:
    1. v2.6.3
    2. v2.7.0
    3. -----------------
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to combine multiple .html files together into one .html

    Try using QTextEdit::append() or control where you insert data using QTextCursor API.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 15th September 2011, 21:25
  2. add .html files to a .qch file?
    By evilbunny in forum Newbie
    Replies: 0
    Last Post: 17th December 2010, 01:27
  3. Replies: 0
    Last Post: 16th April 2010, 11:16
  4. HTML in QTextView
    By genick bar-meir in forum Qt Programming
    Replies: 4
    Last Post: 19th September 2007, 16:59
  5. Is there a widget for display HTML files?
    By JeffJones in forum Newbie
    Replies: 6
    Last Post: 24th May 2007, 19:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.