Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved write in data to html table

    General and Desktop
    3
    3
    521
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      fender last edited by

      good afternoon
      There is an html table
      I need to fill it with data
      You should end up with a table with 5 columns and 5 rows
      But in the end, everything is displayed in one column
      Help find error
      Thanks

      void f(){
          QStringList massoil[size];
      
          _html += QString("<tr><td width=\"100%\" colspan=\"6\"><b><u>Result</u></b></td></tr>");
              _html += QString("<table border=\"1\" border-color=\"white\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">");
                _html += QString("<tr></tr>");
                  if ( cb_mass_oil->isChecked())
                  {
                      for (int col = 0; col < size; ++col)
                          for (int row = 0; row < 5; ++row)
                          {
                              if(row < massoil[col].size())
                                  _html += QString("<tr><td width=\"40%\" align=\"center\" border=\"1\">%0</td></tr>")
                                          .arg(massoil[col][row]);
                              else
                                  _html += QString("<tr><td width=\"40%\" align=\"center\" border=\"1\">%0</td></tr>")
                                          .arg("");
                          }
                         _html.replace(QRegularExpression("<tr(\\s[^>]*)?>(\\s*<td(\\s[^>]*)?>\\s*</td>\\s*)*</tr>", QRegularExpression::MultilineOption), "");
                  }
      1 Reply Last reply Reply Quote 0
      • VRonin
        VRonin last edited by VRonin

        move the row loop outside the column loop and don't close your <tr> tag at every column.
        Well formatted html is a dialect of xml so it's usually cleaner to use QXmlStreamWriter to create html rather than manually piece together strings

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply Reply Quote 2
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          @fender said in write in data to html table:

          QString("<tr><td width="40%" align="center" border="1">%0</td></tr>")

          You are only adding rows with single cells in them.

          The logic would be:

              for each row:
                  add `<tr>` 
                  for each column:
                       add `<td>"whaterever"</td>`
                  add`</tr>`
          

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 1
          • First post
            Last post