Hello Eskil,

Thanks for your help.

I modified your suggested code according to my multithreading needs , but it's 
not working, please have a look and suggest where am I going wrong.

What I tried with your code:

1. I created a pool of WebFrameInThread objects.
2. Then as happens in a server side application, waited for HTML to PDF 
conversion request, 
3. As soon as I received a request, I moved one of the WebFrameInThread objects 
from main thread to child thread and loaded the QUrl provided in the available 
QWebFrame.
4. Unfortunately the above use case is failing.

Please help!!!!

With regards
Ashish Sharma 



-----Original Message-----
From: Eskil Abrahamsen Blomfeldt [mailto:[email protected]] 
Sent: Wednesday, July 08, 2009 4:05 PM
To: Sharma, Ashish
Cc: [email protected]
Subject: Re: [Qt-jambi-interest] Html to pdf conversion

Sharma, Ashish wrote:
>
> Hello,
>
> I am using Qt webkit Jambi API's to convert HTML to PDF.
>
> My target is to create a jar for above conversion so that it could be 
> used in a multithreading environment, but since QWebPage and QWebframe 
> (QT webkit) are GUI classes, therefore the jar classes cannot be 
> initialized from child threads.
>

It's true that certain actions are restricted to the gui thread (such as using 
widgets), but painting to a printer is allowed, as described here:

    
http://doc.trolltech.com/qtjambi-4.5.0_01/com/trolltech/qt/qtjambi-threads.html#painting-in-threads

A restriction on QWebPage is that it has to be constructed in the GUI thread, 
since it accesses QApplication. However, you can use
QObject.moveToThread() to move QObjects over to a different thread than the one 
that created it.

See the attached example of how to make a thread-based web page renderer that 
renders into a .pdf. (it's a quick&dirty example, so please excuse any bugs, 
but it should at least illustrate how to achieve what you need.)

The example makes a widget which monitors the progress of loading the web page. 
The QWebPage is constructed in the gui thread, and made a child of the runnable 
object. Then the entire hierarchy is moved to the thread in question. The run() 
method in the runnable starts loading the web page, and when it completes, the 
web page is rendered into a .pdf-printer and the application is shut down.

> Also i am a novice in QT , can anyone provide good reference about QT 
> application's lifecycle, event loops and related stuff.
>

Threads and event loops are described here:

    
http://doc.trolltech.com/qtjambi-4.5.0_01/com/trolltech/qt/qtjambi-threads.html

And here are a few whitepapers which may contain more information:

    https://www.qtsoftware.com/files/pdf

-- Eskil


Attachment: WebFrameInThread.java
Description: WebFrameInThread.java

_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

Reply via email to