Unfortunately, manually creating the html is the only way.. I believe there may 
be a third party commercial version out there...

Scott

From: [email protected] 
[mailto:[email protected]] 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("&nbsp;"));

                }

            }

            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
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to