QtWebkit multithreading
-
wrote on 22 Aug 2011, 11:07 last edited by
I am working on a project to render text as images using QT-Jambi.
The webkit renders the HTML and generates the image.
While running the code with a single thread there are no issue
but when I run the program using multiple threads(5-6) with each thread making multiple calls the getImage() the code crashesfor each thread I am passing a new QWebPage and using QWebPgae.moveToThread().
@ public void getImage(String str, int width, String fname, boolean istransparent) { QSize qSize = new QSize(width,height); page.setViewportSize(qSize); str = applyStyle(str); page.mainFrame().setHtml(str); String imageName = fname + "_" + width + "x" + page.mainFrame().contentsSize().height() + ".png"; System.out.println("Creating Full Image : " + imageName); page.setViewportSize(page.mainFrame().contentsSize()); QImage qImage = new QImage(page.mainFrame().contentsSize(), QImage.Format.Format_ARGB32); QPainter painter = new QPainter(qImage); page.mainFrame().render(painter); if (istransparent) makeTransparent(qImage); qImage.save(imageName); painter.end(); qImage.dispose(); } @
@
An unexpected error has been detected by Java Runtime Environment:
SIGSEGV (0xb) at pc=0x03534417, pid=6123, tid=1902168976
Java VM: OpenJDK Server VM (1.6.0-b09 mixed mode linux-x86)
Problematic frame:
C [libQtWebKit.so.4+0x567417]
If you would like to submit a bug report, please visit:
http://icedtea.classpath.org/bugzilla
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.
@
@"COMPLETE CORE DUMP AT":http://freetexthost.com/1dtmb03qup
@ -
wrote on 22 Aug 2011, 11:46 last edited by
Please don't double-post. I have deleted the duplicate of this posting that you put in General and Desktop.
-
wrote on 22 Aug 2011, 13:21 last edited by
QtWebkit classes are GUI classes and as such they are meant to be used from the main thread only.
-
wrote on 22 Aug 2011, 13:45 last edited by
I am passing a new instance of QWebPage to each thread
MyClass contains imageGenerator()@.....in main()...
QWepPage page = new QWebPage();
MyClass m = new MyClass();
QThread thread = new QThread(m)page.moveToThread(thread);
thread.start();
.....
@ -
wrote on 22 Aug 2011, 14:11 last edited by
[quote author="ananya" date="1314020743"]I am passing a new instance of QWebPage to each thread
[/quote]I just can emphasize what peppe wrote:
[quote author="peppe" date="1314019276"]QtWebkit classes are GUI classes and as such they are meant to be used from the main thread only.[/quote]
So, you must not move the web page to another thread.
-
wrote on 22 Aug 2011, 14:13 last edited by
Is there any work around for this then? while still keeping it multi threaded?
p.s.
i've found that the part of code that is causing the crash is
@page.mainFrame().setHtml(str);@ -
wrote on 22 Aug 2011, 14:15 last edited by
[quote author="ananya" date="1314022398"]Is there any work around for this then? while still keeping it multi threaded?[/quote]
Sure, if you don't mind what you are trying to achieve, we can give advice.
-
wrote on 22 Aug 2011, 14:20 last edited by
I am trying to make an application to convert text to image ...one requirement is that i should be able to run multiple threads since i plan to integrate this with a web server
-
wrote on 22 Aug 2011, 14:37 last edited by
It's not possible with Qt. Can't you just run multiple processes?
-
wrote on 22 Aug 2011, 23:47 last edited by
All you can do is running multiple threads that collect the data (HTML pages) and send that to the QWebPage instances in the main thread.
-
wrote on 23 Aug 2011, 01:20 last edited by
[quote author="Volker" date="1314056869"]All you can do is running multiple threads that collect the data (HTML pages) and send that to the QWebPage instances in the main thread.[/quote]
that wont really serve my purpose of generating images in parallel
[quote author="peppe" date="1314023870"]It's not possible with Qt. Can't you just run multiple processes?[/quote]
will try to run it as a process..and get back
-
wrote on 23 Aug 2011, 05:07 last edited by
[quote author="ananya" date="1314062413"]
[quote author="Volker" date="1314056869"]All you can do is running multiple threads that collect the data (HTML pages) and send that to the QWebPage instances in the main thread.[/quote]that wont really serve my purpose of generating images in parallel
[quote author="peppe" date="1314023870"]It's not possible with Qt. Can't you just run multiple processes?[/quote]
will try to run it as a process..and get back
[/quote]Suppose i use Callable instead of Runnable threads
Is it possible to initialize a new QApplication within each callable's call...when i'm trying this only the first callable runs..the others crash -
wrote on 23 Aug 2011, 07:09 last edited by
You can only have one Q(Core)Application instance. You might delete the instance and create a new but ... there can be only one!
-
wrote on 8 Feb 2012, 07:06 last edited by
"You can only have one Q(Core)Application instance. You might delete the instance and create a new but … there can be only one!"
How to do this? please help