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

Yuchen Deng loaden at gmail.com
Thu Mar 14 23:11:51 CET 2013


Thanks you very much!

2013/3/15 Scott Aron Bloom <scott.bloom at onshorecs.com>

>  Unfortunately, manually creating the html is the only way.. I believe
> there may be a third party commercial version out thereā€¦****
>
>
> Scott****
>
> ** **
>
> *From:* interest-bounces+scott=onshorecs.com at qt-project.org [mailto:
> interest-bounces+scott=onshorecs.com at qt-project.org] *On Behalf Of *Yuchen
> Deng
> *Sent:* Thursday, March 14, 2013 2:59 AM
> *To:* Qt Project
> *Subject:* [Interest] How to generate HTML tables from QSqlTableModel or
> QStand?****
>
> ** **
>
> 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****
>



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


More information about the Interest mailing list