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