QML WebView load page from cache



  • Hello, it is possible to load page from cache using QML WebView? If there is an Internet connection I want to load page from Internet and if there is no - load page from cache.



  • You can set..
    webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    or open html file like epub file..
    setsource(Qurl("/user/home/ebook/xxx/chapter2/index.html"));
    Save local html page is also possibel..

    
    EpubView::EpubView(QWidget *parent) : QWebEngineView(parent) {
      modusNow = 1;
      this->setMinimumWidth(400);
      this->setMinimumHeight(400);
      this->setContentsMargins(0, 0, 0, 0);
      connect(QWebEngineView::page(), SIGNAL(loadFinished(bool)), this, SLOT(startHtmlGrab(bool)));
    }
    
    void EpubView::startHtmlGrab( bool ok) {
         if (ok) {
             QUrl uri = this->page()->url();
             if (uri.isLocalFile()) {
                connect(this, SIGNAL(incomHtml(QString)), this, SLOT(handleHTML(QString)));
                this->page()->toHtml([this](const QString& result) mutable { emit (void)incomHtml(result);});
             }
         }
    }
    
    

    from
    https://github.com/pehohlva/QOASIS/blob/master/test/dkernel/epubview.cpp

    Oh sorry i dont see QML.....
    QML -> https://doc.qt.io/qt-5/qml-qtwebengine-webengineprofile.html#httpCacheMaximumSize-prop



  • According (QtWebEngine 1.5) property cachePath path to cache by default is StandardPaths.writableLocation(StandardPaths.CacheLocation). Where are some files in that folder and none of them has extention .html (Some files has some JavaScript functions, others css and html tags inside). Is there any way to some how glue them to one page and display by using WebView component (QML)?
    0_1505219546685_Capture1.PNG

    @patrik08


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.