PDA

View Full Version : How to combine multiple .html files together into one .html



stella1016
11th October 2011, 12:52
I am using QTextEdit for this. Method insertHtml() helped. But this method works not as I imagine.

My file1.html is


<html>
<body>
<p>
<h2>title1</h2>

<ul>
<li>bla</li>
<li>bla</li>
</ul>
</p>
<br>
</body>
</html>


File2.html is


<html>
<body>
<p>
<h2>title2</h2>

<ul>
<li>blabla</li>
<li>blabla</li>
</ul>
</p>
<br>
</body>
</html>


My code is:


QString fileName1(":/file1.html");
QFile file1(fileName1);
if (file1.open(QIODevice::ReadOnly))
{
QString data1(file1.readAll());
if (fileName1.endsWith(".html"))
textEdit->insertHtml(data1);
}

QString fileName2(":/file2.html");
QFile file2(fileName2);
if (file2.open(QIODevice::ReadOnly))
{
QString data2(file2.readAll());
if (fileName2.endsWith(".html"))
textEdit->insertHtml(data2);
}


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:


textEdit->insertHtml("<hr>");

The line is beneath the file2's title. crazy!

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

Lykurg
11th October 2011, 13:28
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.

stella1016
11th October 2011, 13:55
It doesn't work. I tried:


QString test1 = "<h2>v2.6.3</h2>";
QString test2 = "<h2>v2.7.0</h2>";

textEdit->insertHtml(test1);
textEdit->insertHtml("<hr>");
textEdit->insertHtml(test2);


The output is:


v2.6.3
v2.7.0
-----------------

wysota
12th October 2011, 06:34
Try using QTextEdit::append() or control where you insert data using QTextCursor API.