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 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>

    jsulmJ JonBJ 2 Replies Last reply
    0
    • G Ghis64

      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>

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on 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

      JonBJ G 2 Replies Last reply
      0
      • G Ghis64

        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>

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on 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
        • jsulmJ jsulm

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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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.

          jsulmJ 1 Reply Last reply
          0
          • jsulmJ jsulm

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

            G Offline
            G Offline
            Ghis64
            wrote on 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.

            jsulmJ 1 Reply Last reply
            0
            • JonBJ JonB

              @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.

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on 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

              JonBJ 1 Reply Last reply
              1
              • G Ghis64

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

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on 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
                1
                • jsulmJ jsulm

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

                  G Offline
                  G Offline
                  Ghis64
                  wrote on 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));
                  
                  jsulmJ 1 Reply Last reply
                  0
                  • G Ghis64

                    @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));
                    
                    jsulmJ Online
                    jsulmJ Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on 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
                    0
                    • jsulmJ jsulm

                      @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 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
                      • jsulmJ jsulm

                        @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.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on 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

                        • Login

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