On Saturday 14 June 2008 10:41:28 [EMAIL PROTECTED] wrote:
> Hi Trolls,
>  I can't use setHtml member of QWebFrame class. For me is not working (see
> the output of  ->> qDebug()<<page.mainFrame()->toHtml();<<-).
> I made an example.
>
> //test.h
>
> #ifndef TEST_H
> #define TEST_H
>
> #include <QWidget>
> #include <QPaintEvent>
> #include <QPainter>
> #include <QWebPage>
> #include <QWebFrame>
> #include <QDebug>
>
> class Test : public QWidget
> {
>       Q_OBJECT
>
> public:
>       Test(QWidget *parent = 0): QWidget(parent){}
> protected:
>       void paintEvent(QPaintEvent * event)
>       {
>               QWidget::paintEvent(event);
>               QPainter painter(this);
>               painter.setRenderHint(QPainter::Antialiasing);
>               painter.translate(50,50);
>               painter.drawText(10,10,"Trolltech");
>               painter.translate(100,100);
>               QWebPage page;
>               page.mainFrame()->setHtml("<b>Trolltech</b>");
>               qDebug()<<page.mainFrame()->toHtml();
> //            page.mainFrame()->render(&painter,geometry());
>               page.mainFrame()->render(&painter);
>       }
> };
>
> #endif
>
> // main.cpp
> #include <QApplication>
> #include "test.h"
>
> int main(int argc, char *argv[])
> {
>       QApplication app(argc, argv);
>       Test t;
>       t.show();
>       return app.exec();
> }
>
> I use qt 4.4.0 (from debian unstable).

Oops, that's a bug. setHtml should set the contents immediately. I've attached 
the patch that fixes this, it will be in Qt 4.4.2.

As a workaround you could call setHtml in the constructor of your class. The 
contents will then be populated into the QWebPage next time the event loop 
spins. That is also much faster than calling setHtml() on every paint event, 
as that parses the HTML every time.


Simon
--- a/src/3rdparty/webkit/WebCore/loader/DocumentLoader.h
+++ b/src/3rdparty/webkit/WebCore/loader/DocumentLoader.h
@@ -155,6 +155,7 @@ namespace WebCore {
 
         void subresourceLoaderFinishedLoadingOnePart(ResourceLoader*);
         
+        void setDeferMainResourceDataLoad(bool defer) { 
m_deferMainResourceDataLoad = defer; }
         bool deferMainResourceDataLoad() const { return 
m_deferMainResourceDataLoad; }
     protected:
         bool m_deferMainResourceDataLoad;
--- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp
+++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp
@@ -774,6 +774,8 @@ bool FrameLoaderClientQt::shouldFallBack(const 
WebCore::ResourceError&)
 WTF::PassRefPtr<WebCore::DocumentLoader> 
FrameLoaderClientQt::createDocumentLoader(const WebCore::ResourceRequest& 
request, const SubstituteData& substituteData)
 {
     RefPtr<DocumentLoader> loader = new DocumentLoader(request, 
substituteData);
+    if (substituteData.isValid())
+        loader->setDeferMainResourceDataLoad(false);
     return loader.release();
 }
 

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Qt4-preview-feedback mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback

Reply via email to