Multiple, identical instances of WebView, dynamically created



  • Hi

    I have a qWebView that is used as GUI. I created it in the Designer and additionally set some things from code. This is about it:

    ui setup for webGUI (generated by compiler after graphical setup):

    	webGUI = new QWebView(centralWidget);
    	webGUI->setObjectName(QString::fromUtf8("webGUI"));
    	webGUI->setGeometry(QRect(280, 190, 150, 120));
    	webGUI->setAcceptDrops(false);
    	webGUI->setStyleSheet(QString::fromUtf8("background-color: rgba(127, 127, 127, 0);"));
    	webGUI->setUrl(QUrl("about:blank"));
    	webGUI->setRenderHints(QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing);
    
      ui->webGUI->page()->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
      ui->webGUI->page()->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
      ui->webGUI->hide();
    

    I'm using the JavaScript Bridge to get inputs(clicks) made in the webGUI into my C++ code and act on it.

    I now need to have multiple, fully identical webViews as selectable GUI's for fast switching between GUI pages without having to always load the new webGUI from the server in a single webView.
    The multiples can be fixed, though it would be a plus to be able to add them at run-time as needed with a limit in quantity.

    What is the best way to do this? Of, course, I could add the same init code like 10 times, but that not really seems an elegant solution. Do I create a new class, or ... ?
    How about the JS Bridge, the same function should be invoked from every instance of the view.

    Thanks for some guidance.



  • Anyone a good suggestion ... ?



  • Forgot to update this .... solved.
    I added code to create GUI's as needed, dynamically.



  • @McLion said in Multiple, identical instances of WebView, dynamically created:

    I now need to have multiple, fully identical webViews as selectable GUI's for fast switching between GUI pages without having to always load the new webGUI from the server in a single webView.

    This is wrong assumption: QtWebKit has multiple tiers of memory caches, so navigation from one page to another will not invoke any network requests in case all resources are cached. (You can also provide disk cache so it could survive application restarts, if needed) In particular look at QWebSettings::setMaximumPagesInCache() - if your UI consists of, say, 5 pages, you should set it to at least 5 to get best performance.

    If you still see that application makes unnecessary network requests because of some resources getting evicted from cache, you may want to tune sizes of other caches, in particular setObjectCacheCapacities()

    Approach with multiple views is optimal when you want all those pages to be present on screen at the same time, or have indpendent "tabs" like in a browser with separate navigation histories and possibility to do background work like playing music



  • @Konstantin-Tokarev said in Multiple, identical instances of WebView, dynamically created:

    Approach with multiple views is optimal when you want all those pages to be present on screen at the same time, or have indpendent "tabs" like in a browser with separate navigation histories and possibility to do background work like playing music

    This is about what we do. The screen is divided into various sections that are used for various menus, sub-menus, lists ... and more. These need to be loaded and shown/hidden separately or at the same time. The GUI is completely based on webpages with html/css/php/js.

    I have it working pretty smart now, though there are some limits like a key can not be sent to a webGUI that is hidden for instance, which would be great to preload a GUI section before showing.


Log in to reply
 

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