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. how to create a sample HTML file using QFIle
Forum Updated to NodeBB v4.3 + New Features

how to create a sample HTML file using QFIle

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 5 Posters 6.3k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 11 Mar 2019, 06:08 last edited by
    #2

    QTextBrowser is using a QTextDocument internally which is responsible for the html in/output

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    M 1 Reply Last reply 11 Mar 2019, 06:12
    0
    • C Christian Ehrlicher
      11 Mar 2019, 06:08

      QTextBrowser is using a QTextDocument internally which is responsible for the html in/output

      M Offline
      M Offline
      ManiRon
      wrote on 11 Mar 2019, 06:12 last edited by
      #3

      @Christian-Ehrlicher i tried with QTextDocument, I am unable to generate file

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 11 Mar 2019, 06:54 last edited by Christian Ehrlicher 3 Nov 2019, 06:55
        #4

        @ManiRon said in how to create a sample HTML file using QFIle:

        I am unable to generate file

        In which way? This is not very precise...

        QTextDocument::toHtml

        And ahy do you delete your topics?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        M 3 Replies Last reply 11 Mar 2019, 06:58
        0
        • C Christian Ehrlicher
          11 Mar 2019, 06:54

          @ManiRon said in how to create a sample HTML file using QFIle:

          I am unable to generate file

          In which way? This is not very precise...

          QTextDocument::toHtml

          And ahy do you delete your topics?

          M Offline
          M Offline
          ManiRon
          wrote on 11 Mar 2019, 06:58 last edited by
          #5

          @Christian-Ehrlicher sorry by mistake

          1 Reply Last reply
          0
          • C Christian Ehrlicher
            11 Mar 2019, 06:54

            @ManiRon said in how to create a sample HTML file using QFIle:

            I am unable to generate file

            In which way? This is not very precise...

            QTextDocument::toHtml

            And ahy do you delete your topics?

            M Offline
            M Offline
            ManiRon
            wrote on 11 Mar 2019, 07:00 last edited by
            #6

            @Christian-Ehrlicher I tried the way you mentioned but it creates file but doesnt have the contents.

            1 Reply Last reply
            0
            • C Christian Ehrlicher
              11 Mar 2019, 06:54

              @ManiRon said in how to create a sample HTML file using QFIle:

              I am unable to generate file

              In which way? This is not very precise...

              QTextDocument::toHtml

              And ahy do you delete your topics?

              M Offline
              M Offline
              ManiRon
              wrote on 11 Mar 2019, 07:01 last edited by ManiRon 3 Nov 2019, 07:02
              #7

              @Christian-Ehrlicher this is my code

                    QTextDocument qData1(&qHtmlFile);
              qData1.setHtml(qRep);
                      qData1.toHtml();
              
              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 11 Mar 2019, 07:03 last edited by
                #8

                How should the code above create a file when there is no QFile involved at all? Please be a little bit more careful and think by yourself before posting some useless stuff.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                M 1 Reply Last reply 11 Mar 2019, 07:07
                1
                • C Christian Ehrlicher
                  11 Mar 2019, 07:03

                  How should the code above create a file when there is no QFile involved at all? Please be a little bit more careful and think by yourself before posting some useless stuff.

                  M Offline
                  M Offline
                  ManiRon
                  wrote on 11 Mar 2019, 07:07 last edited by ManiRon 3 Nov 2019, 07:09
                  #9

                  @Christian-Ehrlicher
                  I thought you would understand as i have mentioned the QFile in my first post itself so i thought its fine to just give the main part , is it fine now ?

                  QFile qHtmlFile("FilePath");
                  QTextDocument qData1(&qHtmlFile);
                  qData1.setHtml(qRep);
                  qData1.toHtml();

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 11 Mar 2019, 07:10 last edited by
                    #10

                    Please read the docs - I gave you the links so you even don't have to search. This can't work at all...

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    M 2 Replies Last reply 11 Mar 2019, 07:11
                    2
                    • C Christian Ehrlicher
                      11 Mar 2019, 07:10

                      Please read the docs - I gave you the links so you even don't have to search. This can't work at all...

                      M Offline
                      M Offline
                      ManiRon
                      wrote on 11 Mar 2019, 07:11 last edited by ManiRon 3 Nov 2019, 07:16
                      #11

                      @Christian-Ehrlicher ok sir, then how this can be done, I mean generating an html file.

                      1 Reply Last reply
                      0
                      • C Christian Ehrlicher
                        11 Mar 2019, 07:10

                        Please read the docs - I gave you the links so you even don't have to search. This can't work at all...

                        M Offline
                        M Offline
                        ManiRon
                        wrote on 11 Mar 2019, 07:20 last edited by
                        #12

                        @Christian-Ehrlicher any other idea if possible

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 11 Mar 2019, 07:29 last edited by
                          #13

                          Hi,

                          Use of QFile:

                          • Create QFile variable
                          • Call open
                          • Check that open was successful
                          • Call write
                          • Close file

                          Done

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

                          M 1 Reply Last reply 11 Mar 2019, 09:15
                          4
                          • S SGaist
                            11 Mar 2019, 07:29

                            Hi,

                            Use of QFile:

                            • Create QFile variable
                            • Call open
                            • Check that open was successful
                            • Call write
                            • Close file

                            Done

                            M Offline
                            M Offline
                            ManiRon
                            wrote on 11 Mar 2019, 09:15 last edited by ManiRon 3 Nov 2019, 09:29
                            #14

                            @SGaist yes i tried it, I create a table using HTML . If i do as mentioned by you the table doesnt has the column seperator line .0_1552296582698_Untitled.jpg

                            J 1 Reply Last reply 11 Mar 2019, 09:30
                            0
                            • M ManiRon
                              11 Mar 2019, 09:15

                              @SGaist yes i tried it, I create a table using HTML . If i do as mentioned by you the table doesnt has the column seperator line .0_1552296582698_Untitled.jpg

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 11 Mar 2019, 09:30 last edited by
                              #15

                              @ManiRon Can you please show the code you're using now? And the content of the file you're generating (the text, not pictures)?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              M 1 Reply Last reply 11 Mar 2019, 09:31
                              0
                              • J jsulm
                                11 Mar 2019, 09:30

                                @ManiRon Can you please show the code you're using now? And the content of the file you're generating (the text, not pictures)?

                                M Offline
                                M Offline
                                ManiRon
                                wrote on 11 Mar 2019, 09:31 last edited by
                                #16

                                @jsulm

                                this whole code will be stored in a QString and this i am printing

                                <article><div align="right"></div><header><h1><center><font color="midnightblue"></font></center></h1><h2><font color="dimgray"></font></h2></header></article><table border="1" style="background-color:ghostwhite;border:1px dotted black;width:80%;border-collapse:collapse;"><tr style="background-color:gainsboro;color:black;"></table><style type="text/css">table.tbl {border-width: 1px;border-style: solid;border-color: black;margin-top: 0px;margin-bottom: 0px;color: black;}table.tbl td {padding: 3px;}table.tbl th {padding: 3px;font-size: 18px;}</style><table width="100%" cellspacing="0" class="tbl" style="border:1px solid black;border-collapse:collapse;" align = center ><tr><th><b><center><span style =font-size:10pt;>Application</span></center></b></th><th><b><center><span style =font-size:10pt;>Check Sum</span></center></b></th><th><b><center><span style =font-size:10pt;>Total</span></center></b></th><th><b><center><span style =font-size:10pt;>No</span></center></b></th><th><b><center><span style =font-size:10pt;>Tested By</span></center></b></th><th><b><center><span style =font-size:10pt;></span></center></b></th><th><b><center><span style =font-size:10pt;></span></center></b></th></tr><tr><td><center><span style =font-size:10pt;>1.00</span></center></td><td><center><span style =font-size:10pt;>123</span></center></td><td><center><span style =font-size:10pt;></span></center></td><td><center><span style =font-size:10pt;></span></center></td><td><center><span style =font-size:10pt;></span></center></td><td><center><span style =font-size:10pt;></span></center></td><td><center><span style =font-size:10pt;></span></center></td></tr></table><br><br><br><style type="text/css">table.tbl1 {border-width: 1px;border-style: solid;border-color: black;margin-top: 0px;margin-bottom: 0px;color: black;}table.tbl1 td {padding: 3px;}table.tbl1 th {padding: 3px;font-size: 18px;}</style><table width="100%" cellspacing="0" class="tbl1"><tr><th>Name</th><th>Data</th><th>data</th><th>Test Result</th></tr><tr><td><b><span style =font-size:10pt;>sss</span></b></td><td>Data1</td><td>Data2</td><td><b><span style =font-size:10pt;><font color=Green>PASS</font></span></b></td></tr></table><br><br><br><br><hr><br><br>

                                J 1 Reply Last reply 11 Mar 2019, 09:33
                                0
                                • M ManiRon
                                  11 Mar 2019, 09:31

                                  @jsulm

                                  this whole code will be stored in a QString and this i am printing

                                  <article><div align="right"></div><header><h1><center><font color="midnightblue"></font></center></h1><h2><font color="dimgray"></font></h2></header></article><table border="1" style="background-color:ghostwhite;border:1px dotted black;width:80%;border-collapse:collapse;"><tr style="background-color:gainsboro;color:black;"></table><style type="text/css">table.tbl {border-width: 1px;border-style: solid;border-color: black;margin-top: 0px;margin-bottom: 0px;color: black;}table.tbl td {padding: 3px;}table.tbl th {padding: 3px;font-size: 18px;}</style><table width="100%" cellspacing="0" class="tbl" style="border:1px solid black;border-collapse:collapse;" align = center ><tr><th><b><center><span style =font-size:10pt;>Application</span></center></b></th><th><b><center><span style =font-size:10pt;>Check Sum</span></center></b></th><th><b><center><span style =font-size:10pt;>Total</span></center></b></th><th><b><center><span style =font-size:10pt;>No</span></center></b></th><th><b><center><span style =font-size:10pt;>Tested By</span></center></b></th><th><b><center><span style =font-size:10pt;></span></center></b></th><th><b><center><span style =font-size:10pt;></span></center></b></th></tr><tr><td><center><span style =font-size:10pt;>1.00</span></center></td><td><center><span style =font-size:10pt;>123</span></center></td><td><center><span style =font-size:10pt;></span></center></td><td><center><span style =font-size:10pt;></span></center></td><td><center><span style =font-size:10pt;></span></center></td><td><center><span style =font-size:10pt;></span></center></td><td><center><span style =font-size:10pt;></span></center></td></tr></table><br><br><br><style type="text/css">table.tbl1 {border-width: 1px;border-style: solid;border-color: black;margin-top: 0px;margin-bottom: 0px;color: black;}table.tbl1 td {padding: 3px;}table.tbl1 th {padding: 3px;font-size: 18px;}</style><table width="100%" cellspacing="0" class="tbl1"><tr><th>Name</th><th>Data</th><th>data</th><th>Test Result</th></tr><tr><td><b><span style =font-size:10pt;>sss</span></b></td><td>Data1</td><td>Data2</td><td><b><span style =font-size:10pt;><font color=Green>PASS</font></span></b></td></tr></table><br><br><br><br><hr><br><br>

                                  J Offline
                                  J Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 11 Mar 2019, 09:33 last edited by jsulm 3 Nov 2019, 09:34
                                  #17

                                  @ManiRon This is not valid HTML.
                                  And by "code" I mean your C++ code to generate the HTML file...

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  M 2 Replies Last reply 11 Mar 2019, 09:37
                                  0
                                  • J jsulm
                                    11 Mar 2019, 09:33

                                    @ManiRon This is not valid HTML.
                                    And by "code" I mean your C++ code to generate the HTML file...

                                    M Offline
                                    M Offline
                                    ManiRon
                                    wrote on 11 Mar 2019, 09:37 last edited by ManiRon 3 Nov 2019, 09:39
                                    #18

                                    @jsulm

                                    QString qHostVer = "<b><center><span style =font-size:10pt;>Application</span></center></b>";

                                    QString qCheckSum = "<b><center><span style =font-size:10pt;>123</span></center></b>";

                                    QString qTotal= "<b><center><span style =font-size:10pt;>Total</span></center></b>";

                                    QString qNo= "<b><center><span style =font-size:10pt;>No</span></center></b>";

                                    QString qTestedBy = "<b><center><span style =font-size:10pt;>Tested By</span></center></b>";

                                             css1 = "<style type=\"text/css\">";
                                             css1 += "table.tbl {border-width: 1px;border-style: solid;border-color: black;margin-top: 0px;margin-bottom: 0px;color: black;}";
                                             css1 += "table.tbl td {padding: 3px;}";
                                             css1 += "table.tbl th {padding: 3px;font-size: 18px;}";
                                             css1+="</style>";
                                             text1 += "<table width=\"100%\" cellspacing=\"0\" class=\"tbl\" style=\"border:1px solid black;border-collapse:collapse;\" align = center >";
                                             text1 +=("<tr><th>"+qHostVer+"</th><th>"+qCheckSum+"</th><th>"+qTargetCheckSum+"</th>"\
                                                      "<th>"+qfont+"</th><th>"+qTestedBy+"</th></tr>");
                                            QString  text1 +=("<tr><td><center><span style =font-size:10pt;>" + 1.00 +"</span></center></td>"\
                                                      "<td><center><span style =font-size:10pt;>" + 123 +"</span></center></td>"\
                                                      "<td><center><span style =font-size:10pt;>" +  +"</span></center></td>"\
                                                      "<td><center><span style =font-size:10pt;>" + o +"</span></center></td>"\
                                                      "<td><center><span style =font-size:10pt;>"+ +"</span></center></td>");
                                    

                                    qRep = css+text;

                                    QFile qHtmlFile(file path);
                                    qHtmlFile.write(qRep);
                                    qHtmlFile.close();

                                    J 1 Reply Last reply 11 Mar 2019, 09:41
                                    0
                                    • J jsulm
                                      11 Mar 2019, 09:33

                                      @ManiRon This is not valid HTML.
                                      And by "code" I mean your C++ code to generate the HTML file...

                                      M Offline
                                      M Offline
                                      ManiRon
                                      wrote on 11 Mar 2019, 09:40 last edited by
                                      #19

                                      @jsulm this code works fine when i use QTextbrowser, But i dont want to use QTextBrowser as it cannot be used inside a QThread

                                      1 Reply Last reply
                                      0
                                      • M ManiRon
                                        11 Mar 2019, 09:37

                                        @jsulm

                                        QString qHostVer = "<b><center><span style =font-size:10pt;>Application</span></center></b>";

                                        QString qCheckSum = "<b><center><span style =font-size:10pt;>123</span></center></b>";

                                        QString qTotal= "<b><center><span style =font-size:10pt;>Total</span></center></b>";

                                        QString qNo= "<b><center><span style =font-size:10pt;>No</span></center></b>";

                                        QString qTestedBy = "<b><center><span style =font-size:10pt;>Tested By</span></center></b>";

                                                 css1 = "<style type=\"text/css\">";
                                                 css1 += "table.tbl {border-width: 1px;border-style: solid;border-color: black;margin-top: 0px;margin-bottom: 0px;color: black;}";
                                                 css1 += "table.tbl td {padding: 3px;}";
                                                 css1 += "table.tbl th {padding: 3px;font-size: 18px;}";
                                                 css1+="</style>";
                                                 text1 += "<table width=\"100%\" cellspacing=\"0\" class=\"tbl\" style=\"border:1px solid black;border-collapse:collapse;\" align = center >";
                                                 text1 +=("<tr><th>"+qHostVer+"</th><th>"+qCheckSum+"</th><th>"+qTargetCheckSum+"</th>"\
                                                          "<th>"+qfont+"</th><th>"+qTestedBy+"</th></tr>");
                                                QString  text1 +=("<tr><td><center><span style =font-size:10pt;>" + 1.00 +"</span></center></td>"\
                                                          "<td><center><span style =font-size:10pt;>" + 123 +"</span></center></td>"\
                                                          "<td><center><span style =font-size:10pt;>" +  +"</span></center></td>"\
                                                          "<td><center><span style =font-size:10pt;>" + o +"</span></center></td>"\
                                                          "<td><center><span style =font-size:10pt;>"+ +"</span></center></td>");
                                        

                                        qRep = css+text;

                                        QFile qHtmlFile(file path);
                                        qHtmlFile.write(qRep);
                                        qHtmlFile.close();

                                        J Offline
                                        J Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on 11 Mar 2019, 09:41 last edited by
                                        #20

                                        @ManiRon You're not generating valid HTML

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        M 1 Reply Last reply 11 Mar 2019, 09:43
                                        0
                                        • J jsulm
                                          11 Mar 2019, 09:41

                                          @ManiRon You're not generating valid HTML

                                          M Offline
                                          M Offline
                                          ManiRon
                                          wrote on 11 Mar 2019, 09:43 last edited by
                                          #21

                                          @jsulm so what change i should make

                                          J 1 Reply Last reply 11 Mar 2019, 09:45
                                          0

                                          11/28

                                          11 Mar 2019, 07:11

                                          • Login

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