1

I'm using Qwebkit and I like to be able to insert into html table each data input that comes last as first record (<tr><td>...my data ...</td></tr>) in to the table. Here is my code this is only example :

ui.webView->page()->mainFrame()->setHtml("<html><body><p>HTML Table Test</p>"
                                            "<table id=\"mainTable\" name=\"mainTable\" BORDER=1 BORDERCOLOR=RED></table>"
                                             "</body></html>");
    QWebElement body = ui.webView->page()->mainFrame()->documentElement();
    QWebElement mainTable = ui.webView->page()->mainFrame()->findFirstElement("#mainTable");
    mainTable.appendInside ("<tr><td>1111111<\/td></\tr>");      ///<-- this is i like to be last in the end
    mainTable.appendInside ("<tr><td>2222222<\/td></\tr>");      ///<-- this is i like to be in the middle
    mainTable.appendInside ("<tr><td>3333333<\/td></\tr>");     ///<-- this is i like to be in the first

The content of the records are coming dynamically and not as I show here, so I can't do it hard coded; in short I need LIFO algorithm here ..

How should I do that ?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user63898
  • 29,839
  • 85
  • 272
  • 514
  • How are your data available in the application? Is it a QVector? QList? Another data structure? – Lohrun May 04 '10 at 12:04

1 Answers1

3

The QWebElement::appendInside method add the parameter to the end of the web element. The QWebElement::prependInside method add the parameter to the beginning of the web element.

If we have a QWebElement *elt containing a empty table such as :

<table><table>

to create the following table,

<table>
  <tr><td>A</td></tr>
  <tr><td>B</td></tr>
  <tr><td>C</td></tr>
</table>

You can use one of the two following methods, they are equivalent.

Method 1, with appendInside

elt->appendInside("<tr><td>A</td></tr>");
elt->appendInside("<tr><td>B</td></tr>");
elt->appendInside("<tr><td>C</td></tr>");

or method 2, with preprendInside

elt->prependInside("<tr><td>C</td></tr>");
elt->prependInside("<tr><td>B</td></tr>");
elt->prependInside("<tr><td>A</td></tr>");

Using prependInside or appendInside gives you the control over the FIFO or LIFO behaviour of your algorithm.

Lohrun
  • 6,432
  • 1
  • 24
  • 22
  • ok i guess i didn't explain .. the content of the records created dynamically , i can't do it hard codded – user63898 May 04 '10 at 10:07
  • 1
    The fact the data aren't hard coded is not relevant in this case, you can replace the string by your own dynamically generated string. I edited my response to highlight the differences between the method you used and the methods I am proposing. – Lohrun May 04 '10 at 12:25