Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QWebEngineView no longer render html files with no .html extension
Forum Updated to NodeBB v4.3 + New Features

QWebEngineView no longer render html files with no .html extension

Scheduled Pinned Locked Moved Unsolved QtWebEngine
11 Posts 3 Posters 2.5k 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.
  • G Offline
    G Offline
    Ghis64
    wrote on 18 Nov 2020, 14:49 last edited by Ghis64
    #1

    Hi,
    Last week my company upgraded the Qt version to Qt5.15.1 and now I have several issues with my code.
    One of them is that the QWebEngineView::load no longer render the html code set in the file: the html code is displayed instead of its rendering.
    After 2 days of investigation I realized that if I add .html at the end of my file name it works!
    It was working with any file name with Qt5.9.
    Is it a regression or is it a new requirement?

    Here is a simple example that illustrate this issue:
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QDialog* dialog = new QDialog (nullptr);
    
    QVBoxLayout* vertLayout = new QVBoxLayout (dialog);
    QDialogButtonBox* buttonBox = new QDialogButtonBox (QDialogButtonBox::Close, dialog);
    
    QWebEngineSettings::globalSettings ()->setAttribute (QWebEngineSettings::AutoLoadImages, true);
    QWebEngineSettings::globalSettings ()->setAttribute (QWebEngineSettings::PluginsEnabled, true);
    QWebEngineSettings::globalSettings ()->setAttribute (QWebEngineSettings::JavascriptEnabled, true);
    
    QWebEngineView* web_view_ = new QWebEngineView (dialog);
    web_view_->setMinimumHeight (500);
    web_view_->setMinimumWidth (700);
    vertLayout->addWidget (web_view_);
    vertLayout->addWidget (buttonBox);
    dialog->connect (buttonBox, SIGNAL (rejected ()), dialog, SLOT (reject ()));
    dialog->resize (QSize (1200, 800));
    
    QString file_name = "C:/Users/XXX/AppData/Local/Temp/report.txt";  // if here I use report.html it works!!
    web_view_->load (QUrl::fromLocalFile (file_name));
    
    dialog->show();
    return a.exec();
    

    }

    and here is the contents of the report.txt file:

    <html>
    <body><h1>Training Set Construction Summary</h1>
    Survey: TEXAS3D@vm -pau-pns-2 <br>
    Domain: Time Migrated<br>
    <br>
    <b>Seismic Attributes : </b><br>
    -Amplitude<br>
    <br>
    Filter out constant value traces : yes<br>
    <br>
    <b>Extraction Geometry</b><br>
    -Top Surface : CHANNELROOF UPGRADE RandD TEXAS3D Picking Interpretation - Offset Above : 0 ms<br>
    <br>
    -Bottom Surface : CHANNELROOF UPGRADE RandD TEXAS3D Picking Interpretation - Offset Below : 20 ms<br>
    <br>
    </body>
    </html>

    J J 2 Replies Last reply 18 Nov 2020, 14:53
    0
    • G Ghis64
      18 Nov 2020, 14:49

      Hi,
      Last week my company upgraded the Qt version to Qt5.15.1 and now I have several issues with my code.
      One of them is that the QWebEngineView::load no longer render the html code set in the file: the html code is displayed instead of its rendering.
      After 2 days of investigation I realized that if I add .html at the end of my file name it works!
      It was working with any file name with Qt5.9.
      Is it a regression or is it a new requirement?

      Here is a simple example that illustrate this issue:
      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);

      QDialog* dialog = new QDialog (nullptr);
      
      QVBoxLayout* vertLayout = new QVBoxLayout (dialog);
      QDialogButtonBox* buttonBox = new QDialogButtonBox (QDialogButtonBox::Close, dialog);
      
      QWebEngineSettings::globalSettings ()->setAttribute (QWebEngineSettings::AutoLoadImages, true);
      QWebEngineSettings::globalSettings ()->setAttribute (QWebEngineSettings::PluginsEnabled, true);
      QWebEngineSettings::globalSettings ()->setAttribute (QWebEngineSettings::JavascriptEnabled, true);
      
      QWebEngineView* web_view_ = new QWebEngineView (dialog);
      web_view_->setMinimumHeight (500);
      web_view_->setMinimumWidth (700);
      vertLayout->addWidget (web_view_);
      vertLayout->addWidget (buttonBox);
      dialog->connect (buttonBox, SIGNAL (rejected ()), dialog, SLOT (reject ()));
      dialog->resize (QSize (1200, 800));
      
      QString file_name = "C:/Users/XXX/AppData/Local/Temp/report.txt";  // if here I use report.html it works!!
      web_view_->load (QUrl::fromLocalFile (file_name));
      
      dialog->show();
      return a.exec();
      

      }

      and here is the contents of the report.txt file:

      <html>
      <body><h1>Training Set Construction Summary</h1>
      Survey: TEXAS3D@vm -pau-pns-2 <br>
      Domain: Time Migrated<br>
      <br>
      <b>Seismic Attributes : </b><br>
      -Amplitude<br>
      <br>
      Filter out constant value traces : yes<br>
      <br>
      <b>Extraction Geometry</b><br>
      -Top Surface : CHANNELROOF UPGRADE RandD TEXAS3D Picking Interpretation - Offset Above : 0 ms<br>
      <br>
      -Bottom Surface : CHANNELROOF UPGRADE RandD TEXAS3D Picking Interpretation - Offset Below : 20 ms<br>
      <br>
      </body>
      </html>

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 18 Nov 2020, 14:53 last edited by
      #2

      @Ghis64 You can use https://doc.qt.io/qt-5/qwebengineview.html#setHtml instead of load()

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

      J G 2 Replies Last reply 18 Nov 2020, 14:59
      0
      • G Ghis64
        18 Nov 2020, 14:49

        Hi,
        Last week my company upgraded the Qt version to Qt5.15.1 and now I have several issues with my code.
        One of them is that the QWebEngineView::load no longer render the html code set in the file: the html code is displayed instead of its rendering.
        After 2 days of investigation I realized that if I add .html at the end of my file name it works!
        It was working with any file name with Qt5.9.
        Is it a regression or is it a new requirement?

        Here is a simple example that illustrate this issue:
        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);

        QDialog* dialog = new QDialog (nullptr);
        
        QVBoxLayout* vertLayout = new QVBoxLayout (dialog);
        QDialogButtonBox* buttonBox = new QDialogButtonBox (QDialogButtonBox::Close, dialog);
        
        QWebEngineSettings::globalSettings ()->setAttribute (QWebEngineSettings::AutoLoadImages, true);
        QWebEngineSettings::globalSettings ()->setAttribute (QWebEngineSettings::PluginsEnabled, true);
        QWebEngineSettings::globalSettings ()->setAttribute (QWebEngineSettings::JavascriptEnabled, true);
        
        QWebEngineView* web_view_ = new QWebEngineView (dialog);
        web_view_->setMinimumHeight (500);
        web_view_->setMinimumWidth (700);
        vertLayout->addWidget (web_view_);
        vertLayout->addWidget (buttonBox);
        dialog->connect (buttonBox, SIGNAL (rejected ()), dialog, SLOT (reject ()));
        dialog->resize (QSize (1200, 800));
        
        QString file_name = "C:/Users/XXX/AppData/Local/Temp/report.txt";  // if here I use report.html it works!!
        web_view_->load (QUrl::fromLocalFile (file_name));
        
        dialog->show();
        return a.exec();
        

        }

        and here is the contents of the report.txt file:

        <html>
        <body><h1>Training Set Construction Summary</h1>
        Survey: TEXAS3D@vm -pau-pns-2 <br>
        Domain: Time Migrated<br>
        <br>
        <b>Seismic Attributes : </b><br>
        -Amplitude<br>
        <br>
        Filter out constant value traces : yes<br>
        <br>
        <b>Extraction Geometry</b><br>
        -Top Surface : CHANNELROOF UPGRADE RandD TEXAS3D Picking Interpretation - Offset Above : 0 ms<br>
        <br>
        -Bottom Surface : CHANNELROOF UPGRADE RandD TEXAS3D Picking Interpretation - Offset Below : 20 ms<br>
        <br>
        </body>
        </html>

        J Offline
        J Offline
        JonB
        wrote on 18 Nov 2020, 14:55 last edited by
        #3

        @Ghis64 said in QWebEngineView no longer render html files with no .html extension:

        One of them is that the QWebEngineView::load no longer render the html code set in the file:

        It was working with any file name with Qt4.9.

        How was that, given that Qt 4 did not have QWebEngine... anything? Must have been miraculous....

        1 Reply Last reply
        1
        • J jsulm
          18 Nov 2020, 14:53

          @Ghis64 You can use https://doc.qt.io/qt-5/qwebengineview.html#setHtml instead of load()

          J Offline
          J Offline
          JonB
          wrote on 18 Nov 2020, 14:59 last edited by JonB
          #4

          @jsulm said in QWebEngineView no longer render html files with no .html extension:

          @Ghis64 You can use https://doc.qt.io/qt-5/qwebengineview.html#setHtml instead of load()

          HI @jsulm. Nonetheless, this does seem to be a "gotcha"! Is it intentional? (Might help if the docs for load() said so?) Does this .htm vs .html behaviour apply to Linux, or is it a Windows-thing only?

          Whoops, I mis-read OP's situation, explained later on below.

          J 1 Reply Last reply 18 Nov 2020, 15:03
          0
          • J jsulm
            18 Nov 2020, 14:53

            @Ghis64 You can use https://doc.qt.io/qt-5/qwebengineview.html#setHtml instead of load()

            G Offline
            G Offline
            Ghis64
            wrote on 18 Nov 2020, 15:02 last edited by
            #5

            @jsulm setHtml has a limit of 2 MB and it fails with some of our files that display plots with a lot of data.

            J 1 Reply Last reply 18 Nov 2020, 15:04
            0
            • J JonB
              18 Nov 2020, 14:59

              @jsulm said in QWebEngineView no longer render html files with no .html extension:

              @Ghis64 You can use https://doc.qt.io/qt-5/qwebengineview.html#setHtml instead of load()

              HI @jsulm. Nonetheless, this does seem to be a "gotcha"! Is it intentional? (Might help if the docs for load() said so?) Does this .htm vs .html behaviour apply to Linux, or is it a Windows-thing only?

              Whoops, I mis-read OP's situation, explained later on below.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 18 Nov 2020, 15:03 last edited by
              #6

              @JonB Sure, it could be documented (and should). I think it simply behaves like any web-broweser: if you enter an URL to a *.txt file the browser will not parse its content, but simply show the text even if it contains valid HTML.

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

              J 1 Reply Last reply 18 Nov 2020, 15:41
              1
              • G Ghis64
                18 Nov 2020, 15:02

                @jsulm setHtml has a limit of 2 MB and it fails with some of our files that display plots with a lot of data.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 18 Nov 2020, 15:04 last edited by
                #7

                @Ghis64 Is there a reason why you name HTML files like text files?

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

                G 1 Reply Last reply 18 Nov 2020, 15:14
                1
                • J jsulm
                  18 Nov 2020, 15:04

                  @Ghis64 Is there a reason why you name HTML files like text files?

                  G Offline
                  G Offline
                  Ghis64
                  wrote on 18 Nov 2020, 15:14 last edited by
                  #8

                  @jsulm In fact in my application code I don't use the .txt extension (I have done like this only in my example). In the application we had this code :
                  QTemporaryFile* tf = new QTemporaryFile (dialog);
                  if (!tf->open ()) {
                  return 0;
                  }

                  tf->write (html_text.toLatin1 ());
                  tf->close ();
                  QString file_name = tf->fileName ();
                  web_view_->load (QUrl::fromLocalFile (file_name));
                  

                  I have replaced it by:

                  QTemporaryFile* tf_html = new QTemporaryFile ("XXXXXX.html", dialog);
                  if (!tf_html->open ()) {
                      return 0;
                  }
                  
                  tf_html->write (html_text.toLatin1 ());
                  tf_html->close ();
                  QString file_name_html = tf_html->fileName ();
                  web_view_->load (QUrl::fromLocalFile (file_name_html));
                  
                  J 1 Reply Last reply 18 Nov 2020, 15:16
                  0
                  • G Ghis64
                    18 Nov 2020, 15:14

                    @jsulm In fact in my application code I don't use the .txt extension (I have done like this only in my example). In the application we had this code :
                    QTemporaryFile* tf = new QTemporaryFile (dialog);
                    if (!tf->open ()) {
                    return 0;
                    }

                    tf->write (html_text.toLatin1 ());
                    tf->close ();
                    QString file_name = tf->fileName ();
                    web_view_->load (QUrl::fromLocalFile (file_name));
                    

                    I have replaced it by:

                    QTemporaryFile* tf_html = new QTemporaryFile ("XXXXXX.html", dialog);
                    if (!tf_html->open ()) {
                        return 0;
                    }
                    
                    tf_html->write (html_text.toLatin1 ());
                    tf_html->close ();
                    QString file_name_html = tf_html->fileName ();
                    web_view_->load (QUrl::fromLocalFile (file_name_html));
                    
                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 18 Nov 2020, 15:16 last edited by
                    #9

                    @Ghis64 said in QWebEngineView no longer render html files with no .html extension:

                    I have replaced it by:

                    Does it work now?

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

                    G 1 Reply Last reply 18 Nov 2020, 15:24
                    0
                    • J jsulm
                      18 Nov 2020, 15:16

                      @Ghis64 said in QWebEngineView no longer render html files with no .html extension:

                      I have replaced it by:

                      Does it work now?

                      G Offline
                      G Offline
                      Ghis64
                      wrote on 18 Nov 2020, 15:24 last edited by
                      #10

                      @jsulm Yes :) But I would have saved a lot of time if it was indicated in the documentation...

                      1 Reply Last reply
                      0
                      • J jsulm
                        18 Nov 2020, 15:03

                        @JonB Sure, it could be documented (and should). I think it simply behaves like any web-broweser: if you enter an URL to a *.txt file the browser will not parse its content, but simply show the text even if it contains valid HTML.

                        J Offline
                        J Offline
                        JonB
                        wrote on 18 Nov 2020, 15:41 last edited by JonB
                        #11

                        @jsulm said in QWebEngineView no longer render html files with no .html extension:

                        @JonB Sure, it could be documented (and should). I think it simply behaves like any web-broweser: if you enter an URL to a *.txt file the browser will not parse its content, but simply show the text even if it contains valid HTML.

                        Sorry, I seem to have quite mis-read what the OP said/meant! I had understood him to be saying he used to use .htm and now found he needs to use .html. Hence my question about Linux vs Windows. But I now see he says nothing of the kind...

                        @Ghis64
                        Now that I understand you had always used .txt. Then it's not a documentation/behaviour issue. Browsers should always open .txt files as text, only .htm or .html should be opened as HTML.

                        1 Reply Last reply
                        1

                        1/11

                        18 Nov 2020, 14:49

                        • Login

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