write in data to html table
Unsolved
General and Desktop
-
wrote on 25 Feb 2020, 10:33 last edited by
good afternoon
There is an html table
I need to fill it with data
You should end up with a table with 5 columns and 5 rows
But in the end, everything is displayed in one column
Help find error
Thanksvoid f(){ QStringList massoil[size]; _html += QString("<tr><td width=\"100%\" colspan=\"6\"><b><u>Result</u></b></td></tr>"); _html += QString("<table border=\"1\" border-color=\"white\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">"); _html += QString("<tr></tr>"); if ( cb_mass_oil->isChecked()) { for (int col = 0; col < size; ++col) for (int row = 0; row < 5; ++row) { if(row < massoil[col].size()) _html += QString("<tr><td width=\"40%\" align=\"center\" border=\"1\">%0</td></tr>") .arg(massoil[col][row]); else _html += QString("<tr><td width=\"40%\" align=\"center\" border=\"1\">%0</td></tr>") .arg(""); } _html.replace(QRegularExpression("<tr(\\s[^>]*)?>(\\s*<td(\\s[^>]*)?>\\s*</td>\\s*)*</tr>", QRegularExpression::MultilineOption), ""); }
-
wrote on 25 Feb 2020, 10:36 last edited by VRonin
move the row loop outside the column loop and don't close your
<tr>
tag at every column.
Well formatted html is a dialect of xml so it's usually cleaner to useQXmlStreamWriter
to create html rather than manually piece together strings -
Hi,
@fender said in write in data to html table:
QString("<tr><td width="40%" align="center" border="1">%0</td></tr>")
You are only adding rows with single cells in them.
The logic would be:
for each row: add `<tr>` for each column: add `<td>"whaterever"</td>` add`</tr>`
1/3