now the problem is different:

  I have a button, when clicked, I start the thumbnail+scale thread. nothing 
happen but I do capture the page load start signal; can not capture the finish 
loading signal;
  then I click the button again, got this error:

QObject::startTimer: timers cannot be started from another thread

I do not see this when first click the button.

 thanks,
canal




________________________________
From: René Jahn <[email protected]>
To: [email protected]
Sent: Fri, August 20, 2010 7:41:16 PM
Subject: Re: [Qt-jambi-interest] Error: QObject used from outside its own thread

 
Are you behind a proxy?
 
 
Von:[email protected] 
[mailto:[email protected]] Im Auftrag von go canal
Gesendet: Freitag, 20. August 2010 12:52
An: Helge Fredriksen
Cc: [email protected]
Betreff: Re: [Qt-jambi-interest] Error: QObject used from outside its own thread
 
Hi,
you are right, I do not need a thread to load a page; what I wanted to do is to 
capture the web page, scale it, and save as an image file. this may takes some 
time and I wanted to put it into a separate thread.
 
I modified a little bit (put new QWebPage() into run() method), the exception 
is 
gone; however, I am not able to capture the loadFinished signal (but can 
capture 
start loading signal):
 
public class Thumbnailer extends QObject implements Runnable {
  QWebPage page;
  String url;
 
  public Thumbnailer (String url) {
     this.url = url;
  }
 
  public void run() {
     page = new QWebPage();  /* <<<< exception if I put this is in the 
constructor */
     page.loadFinished.connect (this, "render(Boolean)");
     page.mainFrame().load(new QUrl(url));
  }
 
  private void renbder (Boolean b) {
    .....
  }
}
 
thanks,
canal
 
 

________________________________
 
From:Helge Fredriksen <[email protected]>
To: go canal <[email protected]>
Cc: [email protected]
Sent: Fri, August 20, 2010 3:17:05 PM
Subject: Re: [Qt-jambi-interest] Error: QObject used from outside its own thread

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

Reply via email to