Hello!
Have you studied the "Hello Webkit" example in our demo application? It
seems that
no extra thread is necessary to load a page, everything happens in the
QWebView.load()
method, and it seems to take place without freezing the UI.
Best regards,
Helge Fredriksen
On 08/20/2010 03:40 AM, go canal wrote:
> Hi Rene,
> Thanks for your sharing. I can access the web, but I have problems
> putting it into a different thread.
>
> What I wanted to do is, upon clicking a button, the slot will create a
> new thread:
> ----
> Thumbnail nail = new Thumbnail (url);
> QThread thread = new QThread (nailer);
> thread.start();
> ----
> I though this is how I should create a new Thread in Qt.
>
> The Thumbnail class is defined as:
>
> public class Thumbnailer extends QObject implements Runnable {
> @Override
> public void run() {
> page.loadFinished.connect(this, "render(Boolean)");
>
> page.mainFrame().load(new QUrl(url));
> }
> ......
> }
>
> But apparently it does not work, exception at
> page.mainFrame().load(new QUrl(url));
>
> I can not figure out what's wrong....
>
> thanks,
> canal
>
>
> ------------------------------------------------------------------------
> *From:* René Jahn <[email protected]>
> *To:* [email protected]
> *Sent:* Thu, August 19, 2010 3:49:11 PM
> *Subject:* Re: [Qt-jambi-interest] Error: QObject used from outside
> its own thread
>
> It should work with following code:
>
> /**
>
> * The <code>Main</code> class handles the web access.
>
> *
>
> * @author René Jahn
>
> */
>
> private static final class Main extends QObject
>
> {
>
>
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> // Class members
>
>
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> /** data loaded event. */
>
> private final
> QSignalEmitter.Signal1<String> loaded = new
> QSignalEmitter.Signal1<String>();
>
> /** reload event. */
>
> private final QSignalEmitter.Signal0
> reload = new QSignalEmitter.Signal0();
>
> /** web view. */
>
> QWebView web;
>
>
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> // Initialization
>
>
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> /**
>
> * Creates a new instance of
> <code>Main</code> and starts reading the
>
> * web page.
>
> */
>
> Main()
>
> {
>
> if
> (System.getProperty("http.proxyHost") != null)
>
> {
>
> try
>
> {
>
>
> QNetworkProxy proxy = new QNetworkProxy(ProxyType.HttpProxy);
>
>
> proxy.setHostName(System.getProperty("http.proxyHost"));
>
>
> proxy.setPort(Integer.parseInt(System.getProperty("http.proxyPort")));
>
>
> QNetworkProxy.setApplicationProxy(proxy);
>
> }
>
> catch
> (Exception e)
>
> {
>
>
> e.printStackTrace();
>
> }
>
> }
>
> web = new QWebView();
>
>
> web.loadFinished.connect(this, "loadFinished(Boolean)");
>
> reload.connect(this,
> "reloadIntern()");
>
> }
>
>
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> // User-defined methods
>
>
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> /**
>
> * Triggers the web page reload.
>
> */
>
> public void reload()
>
> {
>
> //needed to avoid
> threading problems!
>
> reload.emit();
>
> }
>
> /**
>
> * Reloades the web page.
>
> */
>
> @SuppressWarnings("unused")
>
> private void reloadIntern()
>
> {
>
> web.load(new
> QUrl("http://qtjambi.sourceforge.net"));
>
> }
>
> /**
>
> * Forwards the html content to the
> signal handler.
>
> *
>
> * @param pLoaded the loaded state
>
> */
>
> @SuppressWarnings("unused")
>
> private void loadFinished(Boolean pLoaded)
>
> {
>
>
> loaded.emit(web.page().mainFrame().toHtml());
>
> }
>
> } // Main
>
> Regards,
>
> René
>
> *Von:* [email protected]
> [mailto:[email protected]] *Im Auftrag von *go canal
> *Gesendet:* Donnerstag, 19. August 2010 03:38
> *An:* [email protected]
> *Betreff:* [Qt-jambi-interest] Error: QObject used from outside its
> own thread
>
> Hello,
>
> New to Qt Jambi, sorry if this is already been asked before.
>
> I got an exception:
>
> -----------------------------------------------------------
>
> Exception in thread "Thread-2" QObject used from outside its own
> thread, object=QWebPage(0x17b786e8) ,
> objectThread=Thread[main,5,main], currentThread=Thread[Thread-2,5,main]
>
> at
> com.trolltech.qt.GeneratorUtilities.threadCheck(GeneratorUtilities.java:59)
>
> at com.trolltech.qt.webkit.QWebPage.mainFrame(QWebPage.java:619)
>
> at Thumbnailer.run(Thumbnailer.java:44)
>
> at java.lang.Thread.run(Thread.java:619)
>
> at com.trolltech.qt.QThread.run(QThread.java:164)
>
> -----------------------------------------------------------
>
> Could not figure out what's wrong. Here is my code
>
> In the UI_Main :
>
> {
>
> ......
>
> button.clicked.connect(this, "thumb()");
>
> ......
>
> }
>
> void thumb() {
>
> Thumbnailer nailer = new Thumbnailer (lineEdit.text());
>
> QThread thread = new QThread (nailer);
>
> nailer.moveToThread(thread);
>
> thread.start();
>
> }
>
> Here is the Thumbnail class (download a web page and create a
> thumbnail image):
>
> public class Thumbnailer extends QObject implements Runnable {
>
> ......
>
> @Override
>
> public void run() {
>
> page.loadFinished.connect(this, "render(Boolean)");
>
> page.mainFrame().load(new QUrl(url));
>
> }
>
> ......
>
> }
>
> What did I do wrongly ?
>
> many thanks,
> canal
>
>
>
> _______________________________________________
> Qt-jambi-interest mailing list
> [email protected]
> http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest
>
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest