[Solved]How to change dynamically QWebFrame contents?
-
Could you be a little more specific? Do you mean the "load() function":http://doc.qt.nokia.com/4.7-snapshot/qwebframe.html#load ?
-
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
-
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("<html><body>test</body></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("<html><body>test</body></html>"); ui->webView->blockSignals(false);
}
@