无法使用 std::for_each 在 QTextEdit 中构建完整的 html 表
这是我的代码函数:
void ReportHistory::update(void)
{
ui.output->clear();
ui.output->setCurrentFont(QFont("Arial", 8, QFont::Normal));
QString title = "My Title";
QStringList headers = QString("Header1,Header2,Header3,Header4,Header5,Header6").split(",");
QString html = QString(
"<html>" \
"<head>" \
"<meta Content=\"Text/html; charset=Windows-1251\">" \
"<title>%1</title>" \
"</head>" \
"<body bgcolor=#ffffff link=#5000A0>" \
"<p>%1</p>" \
"<table border=1 cellspacing=0 cellpadding=2>" \
"<tr bgcolor=#f0f0f0>"
).arg(title);
foreach (QString header, headers)
{
html.append(QString("<th>%1</th>").arg(header));
}
html.append("</tr>");
struct Fill
{
QString html_;
Analytics::NavHistory::History::value_type prev_;
Fill(QString html) : html_(html)
{}
void operator ()(const Analytics::NavHistory::History::value_type& entry)
{
QStringList line = (QString(
"%1|%2|%3|%4|%5|%6"
).arg(value1, 15)
.arg(value2 ? ' ' : 'C', 8)
.arg(value3, 15)
.arg(value4, 15, 'f', 4)
.arg(value5, 15)
.arg(value6, 15, 'f', 4)).split("|");
html_.append("<tr>");
foreach (QString item, line)
{
html_.append("<td bkcolor=0>%1</td>").arg(item);
}
html_.append("</tr>");
prev_ = entry;
}
};
std::for_each(history_->data().begin(), history_->data().end(), Fill(html));
html.append(
"</table>" \
"</body>" \
"</html>");
ui.output->setHtml(html);
}
其中:
ui.output
是指向 QTextEdit 的指针。
问题:ui.output
只显示标题,而不是完整的表格,有什么问题吗?
谢谢。
Here is my code function:
void ReportHistory::update(void)
{
ui.output->clear();
ui.output->setCurrentFont(QFont("Arial", 8, QFont::Normal));
QString title = "My Title";
QStringList headers = QString("Header1,Header2,Header3,Header4,Header5,Header6").split(",");
QString html = QString(
"<html>" \
"<head>" \
"<meta Content=\"Text/html; charset=Windows-1251\">" \
"<title>%1</title>" \
"</head>" \
"<body bgcolor=#ffffff link=#5000A0>" \
"<p>%1</p>" \
"<table border=1 cellspacing=0 cellpadding=2>" \
"<tr bgcolor=#f0f0f0>"
).arg(title);
foreach (QString header, headers)
{
html.append(QString("<th>%1</th>").arg(header));
}
html.append("</tr>");
struct Fill
{
QString html_;
Analytics::NavHistory::History::value_type prev_;
Fill(QString html) : html_(html)
{}
void operator ()(const Analytics::NavHistory::History::value_type& entry)
{
QStringList line = (QString(
"%1|%2|%3|%4|%5|%6"
).arg(value1, 15)
.arg(value2 ? ' ' : 'C', 8)
.arg(value3, 15)
.arg(value4, 15, 'f', 4)
.arg(value5, 15)
.arg(value6, 15, 'f', 4)).split("|");
html_.append("<tr>");
foreach (QString item, line)
{
html_.append("<td bkcolor=0>%1</td>").arg(item);
}
html_.append("</tr>");
prev_ = entry;
}
};
std::for_each(history_->data().begin(), history_->data().end(), Fill(html));
html.append(
"</table>" \
"</body>" \
"</html>");
ui.output->setHtml(html);
}
Where:
ui.output
is a pointer to QTextEdit.
Question: the ui.output
just show me the headers, and not the full table, what is wrong?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在仿函数中获取
QString
的副本,因此原始版本永远不会被修改。尝试将其更改为,它应该可以工作。
You are taking a copy of the
QString
in your functor and so the original is never modified. Try changing it toand it should work.