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 insert an image in a QFile generated file using HTML
Forum Updated to NodeBB v4.3 + New Features

how to insert an image in a QFile generated file using HTML

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 3 Posters 3.3k 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.
  • M Offline
    M Offline
    ManiRon
    wrote on 21 Feb 2019, 11:33 last edited by ManiRon
    #1

    I am trying to print a Image in a QFile but its not printing and i donno what is the problem
    below is my code

         QString header = "<html>\
          <body>\
           <img src = \"Logo1.png\" alt = \"Test\" >\
            </body>\
          </html>";
    
    
          QFile qHtmlFile(qFileName);
        if(qHtmlFile.open(QIODevice::ReadWrite))
           {
            QTextStream qData(&qHtmlFile);
            qRep = header;
            qTextRep.document()->setHtml(qRep);
            qData << qTextRep.document()->toHtml();
    
                  qDebug("Report Created");
            //      qDebug()<<qRep;
        }
        else
            qDebug() <<qHtmlFile.errorString();
    
        qHtmlFile.close();
    
    J 1 Reply Last reply 21 Feb 2019, 11:57
    0
    • M ManiRon
      21 Feb 2019, 11:33

      I am trying to print a Image in a QFile but its not printing and i donno what is the problem
      below is my code

           QString header = "<html>\
            <body>\
             <img src = \"Logo1.png\" alt = \"Test\" >\
              </body>\
            </html>";
      
      
            QFile qHtmlFile(qFileName);
          if(qHtmlFile.open(QIODevice::ReadWrite))
             {
              QTextStream qData(&qHtmlFile);
              qRep = header;
              qTextRep.document()->setHtml(qRep);
              qData << qTextRep.document()->toHtml();
      
                    qDebug("Report Created");
              //      qDebug()<<qRep;
          }
          else
              qDebug() <<qHtmlFile.errorString();
      
          qHtmlFile.close();
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 21 Feb 2019, 11:57 last edited by
      #2

      @ManiRon How do you actually print? Also, you're using a relative path to the image in your HTML, depending on the current directory at runtime it will or will not be found.

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

      M 1 Reply Last reply 21 Feb 2019, 12:15
      0
      • J jsulm
        21 Feb 2019, 11:57

        @ManiRon How do you actually print? Also, you're using a relative path to the image in your HTML, depending on the current directory at runtime it will or will not be found.

        M Offline
        M Offline
        ManiRon
        wrote on 21 Feb 2019, 12:15 last edited by
        #3

        @jsulm I have defined path also but the image is not displaying , whether we cannot display a image in a file using QFile concept?

        J 1 Reply Last reply 21 Feb 2019, 12:17
        0
        • M ManiRon
          21 Feb 2019, 12:15

          @jsulm I have defined path also but the image is not displaying , whether we cannot display a image in a file using QFile concept?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 21 Feb 2019, 12:17 last edited by jsulm
          #4

          @ManiRon I still don't understand what exactly you're doing: first you say you want to print, now you say you want to display. Can you explain what exactly you're trying to do?
          An image file is not directly part of a HTML document. A HTML document can reference images, but these images are stored in files, not in a HTML document. So, I don't know what you expect to see.

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

          M 1 Reply Last reply 21 Feb 2019, 12:25
          1
          • J jsulm
            21 Feb 2019, 12:17

            @ManiRon I still don't understand what exactly you're doing: first you say you want to print, now you say you want to display. Can you explain what exactly you're trying to do?
            An image file is not directly part of a HTML document. A HTML document can reference images, but these images are stored in files, not in a HTML document. So, I don't know what you expect to see.

            M Offline
            M Offline
            ManiRon
            wrote on 21 Feb 2019, 12:25 last edited by ManiRon
            #5

            @jsulm

            I want to create a report in which i want to display an logo . I have opened a document using Qfile and i am writing data and creating table in that file using html so similarly i want to display the logo in that file . Ya exactly i create an HTML report and want to show or display or print a logo in that file which i am not able to do

            J J 2 Replies Last reply 21 Feb 2019, 12:49
            0
            • M ManiRon
              21 Feb 2019, 12:25

              @jsulm

              I want to create a report in which i want to display an logo . I have opened a document using Qfile and i am writing data and creating table in that file using html so similarly i want to display the logo in that file . Ya exactly i create an HTML report and want to show or display or print a logo in that file which i am not able to do

              J Online
              J Online
              JonB
              wrote on 21 Feb 2019, 12:49 last edited by JonB
              #6

              @ManiRon
              Like @jsulm I am still at a loss about what you are asking. I don't know what your code is about either, it opens files (for read/write at that), then doesn't use them....

              All you can do is if your HTML contains

              <img src="Logo1.png" alt="Test" >
              

              then there needs to be a file named Logo1.png in the directory where that HTML is executed from. How it gets there is irrelevant: it might be something already there, you might create it from code, I don't know, but that's what you need. QFile is not needed, and cannot somehow be "passed" to HTML.

              M 1 Reply Last reply 22 Feb 2019, 05:18
              2
              • J JonB
                21 Feb 2019, 12:49

                @ManiRon
                Like @jsulm I am still at a loss about what you are asking. I don't know what your code is about either, it opens files (for read/write at that), then doesn't use them....

                All you can do is if your HTML contains

                <img src="Logo1.png" alt="Test" >
                

                then there needs to be a file named Logo1.png in the directory where that HTML is executed from. How it gets there is irrelevant: it might be something already there, you might create it from code, I don't know, but that's what you need. QFile is not needed, and cannot somehow be "passed" to HTML.

                M Offline
                M Offline
                ManiRon
                wrote on 22 Feb 2019, 05:18 last edited by
                #7

                @JonB said in how to insert an image in a QFile generated file using HTML:

                <img src="Logo1.png" alt="Test" >

                could you please give an example for printing the image using html in a html file using QFile concept in QT

                1 Reply Last reply
                0
                • M ManiRon
                  21 Feb 2019, 12:25

                  @jsulm

                  I want to create a report in which i want to display an logo . I have opened a document using Qfile and i am writing data and creating table in that file using html so similarly i want to display the logo in that file . Ya exactly i create an HTML report and want to show or display or print a logo in that file which i am not able to do

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 22 Feb 2019, 05:20 last edited by
                  #8

                  @ManiRon If you don't explain how you're showing or printing your report nobody will be able to help you...
                  Is this "printing" you mean

                  qData << qTextRep.document()->toHtml();
                  

                  ?
                  To display this report you can simply open the HTML document in a web browser (the picture must be in the same directory as the HTML document!). Or show it in Qt Web Engine.

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

                  M 2 Replies Last reply 22 Feb 2019, 05:34
                  0
                  • J jsulm
                    22 Feb 2019, 05:20

                    @ManiRon If you don't explain how you're showing or printing your report nobody will be able to help you...
                    Is this "printing" you mean

                    qData << qTextRep.document()->toHtml();
                    

                    ?
                    To display this report you can simply open the HTML document in a web browser (the picture must be in the same directory as the HTML document!). Or show it in Qt Web Engine.

                    M Offline
                    M Offline
                    ManiRon
                    wrote on 22 Feb 2019, 05:34 last edited by
                    #9

                    @jsulm actually i might have to print some data also thats why i am asking, may be i will show my report how it looks

                    J 1 Reply Last reply 22 Feb 2019, 05:38
                    0
                    • M ManiRon
                      22 Feb 2019, 05:34

                      @jsulm actually i might have to print some data also thats why i am asking, may be i will show my report how it looks

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 22 Feb 2019, 05:38 last edited by
                      #10

                      @ManiRon The code you posted does not print anything (except HTML text to the console), so I'm not sure what your question currently is...
                      Just to be sure: by "printing" you mean print on a printer?

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

                      M 1 Reply Last reply 22 Feb 2019, 05:51
                      0
                      • J jsulm
                        22 Feb 2019, 05:20

                        @ManiRon If you don't explain how you're showing or printing your report nobody will be able to help you...
                        Is this "printing" you mean

                        qData << qTextRep.document()->toHtml();
                        

                        ?
                        To display this report you can simply open the HTML document in a web browser (the picture must be in the same directory as the HTML document!). Or show it in Qt Web Engine.

                        M Offline
                        M Offline
                        ManiRon
                        wrote on 22 Feb 2019, 05:42 last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • J jsulm
                          22 Feb 2019, 05:38

                          @ManiRon The code you posted does not print anything (except HTML text to the console), so I'm not sure what your question currently is...
                          Just to be sure: by "printing" you mean print on a printer?

                          M Offline
                          M Offline
                          ManiRon
                          wrote on 22 Feb 2019, 05:51 last edited by
                          #12

                          @jsulm No sir, I will generate a html file with that code but in that html code i want to place or display an image . I tried but its not displaying

                          J 1 Reply Last reply 22 Feb 2019, 05:54
                          0
                          • M ManiRon
                            22 Feb 2019, 05:51

                            @jsulm No sir, I will generate a html file with that code but in that html code i want to place or display an image . I tried but its not displaying

                            J Offline
                            J Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on 22 Feb 2019, 05:54 last edited by
                            #13

                            @ManiRon said in how to insert an image in a QFile generated file using HTML:

                            I tried but its not displaying

                            So, I guess by "displaying" you mean in a web browser?
                            Where exactly is the image file located? Is it in the same directory as the HTML file?

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

                            M 1 Reply Last reply 22 Feb 2019, 05:54
                            0
                            • J jsulm
                              22 Feb 2019, 05:54

                              @ManiRon said in how to insert an image in a QFile generated file using HTML:

                              I tried but its not displaying

                              So, I guess by "displaying" you mean in a web browser?
                              Where exactly is the image file located? Is it in the same directory as the HTML file?

                              M Offline
                              M Offline
                              ManiRon
                              wrote on 22 Feb 2019, 05:54 last edited by
                              #14

                              @jsulm yes

                              J 1 Reply Last reply 22 Feb 2019, 05:55
                              0
                              • M ManiRon
                                22 Feb 2019, 05:54

                                @jsulm yes

                                J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 22 Feb 2019, 05:55 last edited by
                                #15

                                @ManiRon I asked 3 questions. To which question does "yes" belong?

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

                                M 2 Replies Last reply 22 Feb 2019, 05:59
                                0
                                • J jsulm
                                  22 Feb 2019, 05:55

                                  @ManiRon I asked 3 questions. To which question does "yes" belong?

                                  M Offline
                                  M Offline
                                  ManiRon
                                  wrote on 22 Feb 2019, 05:59 last edited by
                                  #16

                                  @jsulm

                                  So, I guess by "displaying" you mean in a web browser? yes
                                  Where exactly is the image file located? from where i am running my application
                                  Is it in the same directory as the HTML file? No

                                  J 1 Reply Last reply 22 Feb 2019, 06:00
                                  0
                                  • M ManiRon
                                    22 Feb 2019, 05:59

                                    @jsulm

                                    So, I guess by "displaying" you mean in a web browser? yes
                                    Where exactly is the image file located? from where i am running my application
                                    Is it in the same directory as the HTML file? No

                                    J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 22 Feb 2019, 06:00 last edited by
                                    #17

                                    @ManiRon said in how to insert an image in a QFile generated file using HTML:

                                    Is it in the same directory as the HTML file? No

                                    Well, then I would say this is the problem (and I already said that before: "the picture must be in the same directory as the HTML document!").

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

                                    M 1 Reply Last reply 22 Feb 2019, 06:05
                                    0
                                    • J jsulm
                                      22 Feb 2019, 05:55

                                      @ManiRon I asked 3 questions. To which question does "yes" belong?

                                      M Offline
                                      M Offline
                                      ManiRon
                                      wrote on 22 Feb 2019, 06:01 last edited by
                                      #18

                                      @jsulm if i simply give this <img src="Logo1.png" alt="Test" > i have to place my image at place where i am saving my html file . But if i give the path its not accepting at all(means its not showing the image at all)

                                      J 1 Reply Last reply 22 Feb 2019, 06:06
                                      0
                                      • J jsulm
                                        22 Feb 2019, 06:00

                                        @ManiRon said in how to insert an image in a QFile generated file using HTML:

                                        Is it in the same directory as the HTML file? No

                                        Well, then I would say this is the problem (and I already said that before: "the picture must be in the same directory as the HTML document!").

                                        M Offline
                                        M Offline
                                        ManiRon
                                        wrote on 22 Feb 2019, 06:05 last edited by ManiRon
                                        #19

                                        @jsulm
                                        QString Header = "<img src="D:/APP/Image" alt="Test" >";

                                        Like this if i mention its not displaying the image

                                        1 Reply Last reply
                                        0
                                        • M ManiRon
                                          22 Feb 2019, 06:01

                                          @jsulm if i simply give this <img src="Logo1.png" alt="Test" > i have to place my image at place where i am saving my html file . But if i give the path its not accepting at all(means its not showing the image at all)

                                          J Offline
                                          J Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on 22 Feb 2019, 06:06 last edited by
                                          #20

                                          @ManiRon "i have to place my image at place where i am saving my html file" - yes!
                                          How can web browser know where the picture is if the only information you give it is the file name without path:

                                          <img src="Logo1.png" alt="Test" >
                                          

                                          ?! So, where should web browser look for this picture?
                                          "But if i give the path its not accepting at all" - how do you give it the path? Please show...

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

                                          M 2 Replies Last reply 22 Feb 2019, 06:07
                                          0

                                          1/24

                                          21 Feb 2019, 11:33

                                          • Login

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