Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. write in data to html table
Forum Update on Monday, May 27th 2025

write in data to html table

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 813 Views
  • 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 Offline
    F Offline
    fender
    wrote on 25 Feb 2020, 10:33 last edited by
    #1

    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
    0
    • V Offline
      V Offline
      VRonin
      wrote on 25 Feb 2020, 10:36 last edited by VRonin
      #2

      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
      2
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 25 Feb 2020, 10:38 last edited by
        #3

        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
        1

        1/3

        25 Feb 2020, 10:33

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved