[Interest] How to generate HTML tables from QSqlTableModel or QStand?

Yuchen Deng loaden at gmail.com
Thu Mar 14 10:59:05 CET 2013


Hi, list!
I wish to using QSqlTableModel in my C++ project, using QTableView for my
Desktop project, and generate the HTML tables for my Web project.
For now I just find the only way like this:

QTextStream out(&file);
>
>         const xbLong rowCount = tableView->model()->rowCount();
>         const xbLong columnCount = tableView->model()->columnCount();
>
>         out <<  "<html>\n"
>                 "<head>\n"
>                 "<meta Content=\"Text/html; charset=Windows-936\">\n"
>             <<  QString("<title>%1</title>\n").arg(refTitleName)
>             <<  "</head>\n"
>                 "<body bgcolor=#ffffff link=#5000A0>\n"
>                 "<table border=1 cellspacing=0 cellpadding=2>\n";
>
>         // headers
>         out << "<tr bgcolor=#f0f0f0>";
>         for (xbLong column = 0; column < columnCount; column++)
>             if (!tableView->isColumnHidden(column))
>                 out << QString("<th>%1</th>").arg(tableView->model()->headerData(column, Qt::Horizontal).toString());
>         out << "</tr>\n";
>         file.flush();
>
>         // data table
>         for (xbLong row = 0; row < rowCount; row++) {
>             out << "<tr>";
>             for (xbLong column = 0; column < columnCount; column++) {
>                 if (!tableView->isColumnHidden(column)) {
>                     QString data = tableView->model()->data(tableView->model()->index(row, column)).toString().simplified();
>                     out << QString("<td bkcolor=0>%1</td>").arg((!data.isEmpty()) ? data : QString(" "));
>                 }
>             }
>             out << "</tr>\n";
>         }
>         out <<  "</table>\n"
>             "</body>\n"
>             "</html>\n";
>
> It's should work, but I think it is not better.
So does there exist a better solution to solved my question?
Or, some exist project? class? extension?

Any comments are welcome!
Thank you!

-- 
Best Regards
Yuchen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130314/8890aaa1/attachment.html>


More information about the Interest mailing list