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. QTWebEngineView doesn't load QRC html files (C++)
QtWS25 Last Chance

QTWebEngineView doesn't load QRC html files (C++)

Scheduled Pinned Locked Moved Unsolved QtWebEngine
c++qrcqwebengineqwebengineviewqurl
5 Posts 2 Posters 1.7k 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.
  • P Offline
    P Offline
    peterkmoss
    wrote on last edited by
    #1

    Hi,

    I'm working on a simple markdown viewer which uses the QtWebEngineView to render the HTML generated and it was working fine until recently, might be due to an update? (I'm currently compiling using 5.15.2)

    I don't know the exact problem but it seems that when I try to tell the QWebEngineView to load or setUrl to a HTML file from my QRC it doesn't show anything - it's just a white screen.

    If I try loading "https://google.com" everything loads correctly - and even other files from the QRC works (!?) I can load a .css file in from the QRC without issues and it will show the CSS in the window that I create, but not HTML.

    Does anyone have any ideas? I've even tried with the most basic index.html file that I could think of...

    This is my MainWindow constructor (at least the relevant parts):

    MainWindow::MainWindow(QString *index_file, QString *file, QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow) {
      m_ui->setupUi(this);
    
      ...
    
      m_file = new QFile(get_file(*file));
    
      m_channel = new QWebChannel(this);
      m_channel->registerObject(QStringLiteral("content"), &m_content);
    
      m_page = new WebPage(this);
      m_page->setWebChannel(m_channel);
    
      m_ui->WebView->setPage(m_page);
      ....
    
      QUrl file_url(*index_file);
      m_ui->WebView->setUrl(file_url);
      ....
    }
    

    The whole code is available here: GitHub, but I can post relevant parts if need be.

    Thanks in advance!

    eyllanescE 1 Reply Last reply
    0
    • P peterkmoss

      Hi,

      I'm working on a simple markdown viewer which uses the QtWebEngineView to render the HTML generated and it was working fine until recently, might be due to an update? (I'm currently compiling using 5.15.2)

      I don't know the exact problem but it seems that when I try to tell the QWebEngineView to load or setUrl to a HTML file from my QRC it doesn't show anything - it's just a white screen.

      If I try loading "https://google.com" everything loads correctly - and even other files from the QRC works (!?) I can load a .css file in from the QRC without issues and it will show the CSS in the window that I create, but not HTML.

      Does anyone have any ideas? I've even tried with the most basic index.html file that I could think of...

      This is my MainWindow constructor (at least the relevant parts):

      MainWindow::MainWindow(QString *index_file, QString *file, QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow) {
        m_ui->setupUi(this);
      
        ...
      
        m_file = new QFile(get_file(*file));
      
        m_channel = new QWebChannel(this);
        m_channel->registerObject(QStringLiteral("content"), &m_content);
      
        m_page = new WebPage(this);
        m_page->setWebChannel(m_channel);
      
        m_ui->WebView->setPage(m_page);
        ....
      
        QUrl file_url(*index_file);
        m_ui->WebView->setUrl(file_url);
        ....
      }
      

      The whole code is available here: GitHub, but I can post relevant parts if need be.

      Thanks in advance!

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @peterkmoss You have to set the resource schema, in the case of qresource you have to use qrc:

      "qrc:/index-light.html";
      "qrc:/index-dark.html";
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        peterkmoss
        wrote on last edited by
        #3

        I'm using a QUrl of "qrc:/index-light.html" and my QRC file looks like this:

        <!DOCTYPE RCC><RCC version="1.0">
            <qresource prefix="/">
                <file>help.md</file>
                <file>index-dark.html</file>
                <file>index-light.html</file>
                <file>colors.css</file>
                <file>light.css</file>
                <file>dark.css</file>
                <file>markdown.css</file>
                <file>3rdparty/marked.js</file>
                <file>3rdparty/prism.js</file>
                <file>3rdparty/prism.css</file>
            </qresource>
        </RCC>
        

        It also doesn't say that it can't find the file - so it clearly knows that there is a html-file, it just doesn't show it?

        eyllanescE 1 Reply Last reply
        0
        • P peterkmoss

          I'm using a QUrl of "qrc:/index-light.html" and my QRC file looks like this:

          <!DOCTYPE RCC><RCC version="1.0">
              <qresource prefix="/">
                  <file>help.md</file>
                  <file>index-dark.html</file>
                  <file>index-light.html</file>
                  <file>colors.css</file>
                  <file>light.css</file>
                  <file>dark.css</file>
                  <file>markdown.css</file>
                  <file>3rdparty/marked.js</file>
                  <file>3rdparty/prism.js</file>
                  <file>3rdparty/prism.css</file>
              </qresource>
          </RCC>
          

          It also doesn't say that it can't find the file - so it clearly knows that there is a html-file, it just doesn't show it?

          eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by eyllanesc
          #4

          @peterkmoss According to your code no:

          // https://github.com/Peterkmoss/qmarkdown/blob/fix-not-loading-index-file/src/main.cpp#L26
          *index_file = ":/index-light.html";
          
          // https://github.com/Peterkmoss/qmarkdown/blob/fix-not-loading-index-file/src/main.cpp#L30
          *index_file = ":/index-dark.html";
          

          I recommend using qDebug() to see what is failing, for example in your case: `

          QUrl file_url(*index_file);
          qDebug() << url;
          m_ui->WebView->setUrl(file_url);
          

          Have you tried changing to : *index_file = "qrc:/index-light.html"; and *index_file = "qrc:/index-dark.html"; in main.cpp?

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            peterkmoss
            wrote on last edited by
            #5

            First off, thanks for your time.

            I've tried that yeah - you can see that I've made the default index_file "qrc:/index-light.html" in the load_args function. It's here in the code.

            When writing to qDebug() the string is correctly "qrc:/index-light.html", though nothing is shown in the webview... I've tried changing it to "qrc:/light.css" and then it correctly shows the css in the webview (the code in plaintext).

            1 Reply Last reply
            0

            • Login

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