[webkit-qt] QObject: Cannot create children for a parent that is in a different thread

sarvesh saran aquarian.thunder at gmail.com
Wed Mar 23 01:47:17 PDT 2011


2011/3/23 周鹏 <zhoupeng19 at 126.com>

>  Hi,all!
>   This is my program,it's create a child thread to get the content of a
> url,but I got the following error output:
>      QObject: Cannot create children for a parent that is in a different
> thread.
>     (Parent is QWebPage(0x94fa350), parent's thread is QThread(0x93b04a8),
> current thread is Thread(0xbff5d33c)
>
> The QThread object (and all its member variables and all things created in
your (QThread subclass's) constructor belong to the thread the QThread
object is created in.

QObjects have an affinity with a single thread. This is usually the thread
that creates the QObject So if you create a QObject  in the app's main
thread and want to use it in another thread, you need to use moveToThread()  to
change the affinity.This saves having to subclass QThread and creating your
objects in the run() method, thus keeping your stuff nicely encapsulated.

Read this:
http://labs.qt.nokia.com/2006/12/04/threading-without-the-headache/

thanks,

Sarvesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-qt/attachments/20110323/9e17ff20/attachment.html>


More information about the webkit-qt mailing list