views:

31

answers:

1

Hi. 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.

+2  A: 

You are taking a copy of the QString in your functor and so the original is never modified. Try changing it to

struct Fill
{
    QString& html_;

    Analytics::NavHistory::History::value_type prev_;

    Fill(QString& html) : html_(html)
    {}

   // etc...
};

and it should work.

Troubadour
@Troubadour +` Thanks!
mosg