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 load HTML file to DataBase
Forum Updated to NodeBB v4.3 + New Features

How load HTML file to DataBase

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 1.7k Views 2 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #6

    Hi
    So the jpg files lives in
    C:\tempDirHtmlResume\tempResumeHtmlFile.files\

    so the task is to save the HTML AND the images to a (sqllite) database ?

    and later be able to load a HTML With the images and show in Qt app ?

    The main issues is that the html is pointing to disk for these files.
    So when you later load the HTML from database, the images MUST be in that location
    to be shown.

    So you also want to save the jpg files to the database ?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mikeeeeee
      wrote on last edited by Mikeeeeee
      #7

      @mrjj said in How load HTML file to DataBase:

      Yes. I am nedd load to DataBase text and images, and after used it's in program.

      mrjjM 1 Reply Last reply
      0
      • M Mikeeeeee

        @mrjj said in How load HTML file to DataBase:

        Yes. I am nedd load to DataBase text and images, and after used it's in program.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #8

        @Mikeeeeee

        Ok, this is not easy. Images MUST be saved in database ?

        1: find the images in the HTML to be able to store in database
        https://stackoverflow.com/questions/51252529/how-to-get-the-src-of-an-image-tag-using-qregexp-and-qstring

        2: save the images into the database , see here.
        https://wiki.qt.io/How_to_Store_and_Retrieve_Image_on_SQLite

        3:
        When loading an HTML, you must the take all images that it has. ( you must store this info somehow)
        and copy each image back to the
        c:\tempDirHtmlResume\tempResumeHtmlFile.files\
        location.
        Else the img src="file:/// no longer work.

        Alternatively, you must change the HTML to point to other location, where you then copy the images.

        But just saving the HTML til database, wont save the images with it. so if you really, really want to store the images in db,
        then you need to handle that yourself.

        1 Reply Last reply
        1
        • M Offline
          M Offline
          Mikeeeeee
          wrote on last edited by
          #9

          In QT, there are no classes that can use text and a picture? For example QTextDocument?

          mrjjM 1 Reply Last reply
          0
          • M Mikeeeeee

            In QT, there are no classes that can use text and a picture? For example QTextDocument?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #10

            @Mikeeeeee
            well it can use it, but it links to files also.
            Images are never embedded in the rich text as far as i know.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #11

              Hi
              What type of app are you making ?
              You could also print the HTML to pdf and save pdf in databse.
              Then images would be included in that case.
              But it would not be HTML nor would images be editable in any way. ever.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #12

                Hi,

                If you want to have an independent page, you would have to integrated your images as base64 encoded, but that's going to make them heavy.

                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
                • M Offline
                  M Offline
                  Mikeeeeee
                  wrote on last edited by
                  #13
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mikeeeeee
                    wrote on last edited by Mikeeeeee
                    #14

                    I converted the picture into text

                    //convert image to string
                        QImage imageForResume("C:\\tempDirHtmlResume\\tempResumeHtmlFile.files\\image001.jpg");
                        QByteArray byteArrayForImage;
                        QBuffer buffer(&byteArrayForImage);
                        imageForResume.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer
                        QString textImage = byteArrayForImage.toBase64();```
                    
                    I have HTML-file QString HTMLResume;
                    How to insert textImage in HTMLResume?
                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Mikeeeeee
                      wrote on last edited by
                      #15

                      It's work:

                          QImage imageForResume("C:\\tempDirHtmlResume\\tempResumeHtmlFile.files\\image001.jpg");
                          QByteArray byteArrayForImage;
                          QBuffer buffer(&byteArrayForImage);
                          imageForResume.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer
                          QString textImage = byteArrayForImage.toBase64();
                          HTMLResume.replace(QRegExp("src=\"tempResumeHtmlFile.files/image001.jpg\">"), " src=\"data:image/png;base64," + textImage + "\"/>"); //замена символов //add text Images
                          ui->ResumeHHTextEdit->setHtml(HTMLResume);
                      
                      1 Reply Last reply
                      1

                      • Login

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