[Solved]How to change dynamically QWebFrame contents?



  • Dear all friends,

    I would like to know how to change dynamically QWebFrame contents?

    Thanks



  • Could you be a little more specific? Do you mean the "load() function":http://doc.qt.nokia.com/4.7-snapshot/qwebframe.html#load ?



  • No, I want to set setHtml() function & want to show newly set html on webframe...
    Thanks



  • Well, AFAIK, setHtml should change the content immediately. If you are looking for a widget (not a frame inside an already exiting Page/Widget), you should use "QWebView":http://doc.qt.nokia.com/4.7-snapshot/qwebview.html



  • Here is code. WebView is abstract of QWebView

    @void WebView::loadFinished()
    {
    page()->mainFrame()->setHtml(newHtml);
    }
    @
    I want to change html after finished loading of that page
    Thanks



  • I found some reason,
    I set view-> setHtml(newHtml);

    They change but, change to original just after finished
    I think that may connect with changeUrl signal but I can't find out..

    Plz help me
    Thanks



  • Hi zither,

    Could you post the related code of your WebView. Firstly, the setHtml will cause the loadFinished signal to be posted again, causing an infinite loop. I have attached working code of what you want to do.

    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    #include <QtWebKit/QWebView>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    connect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(slotloadFinished(bool)));
    
    ui->webView->load(QUrl("http://www.google.com"));
    

    }

    MainWindow::~MainWindow()
    {
    disconnect(ui->webView, 0, this, 0);

    delete ui;
    

    }

    void MainWindow::slotloadFinished(bool okay)
    {
    disconnect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(slotloadFinished(bool)));

    ui->webView->setHtml("&lt;html&gt;&lt;body>test&lt;/body&gt;&lt;/html>");
    
    connect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(slotloadFinished(bool)));
    

    }
    @



  • Instead of the disconnect and connect, you could do this..

    @
    void MainWindow::slotloadFinished(bool okay)
    {
    ui->webView->blockSignals(true);

    ui->webView->setHtml("&lt;html&gt;&lt;body>test&lt;/body&gt;&lt;/html>");
    
    ui->webView->blockSignals(false);
    

    }
    @



  • It's work.. :)
    Thanks to all



  • Good to hear that. Also, could you please add [Solved] in front of the title (by editing the first post).


Log in to reply
 

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