[Qt-interest] QThread eventloop problems
Thiago Macieira
thiago at kde.org
Thu Feb 25 19:03:44 CET 2010
Em Quinta-feira 25 Fevereiro 2010, às 18:50:20, Sergey Shekyan escreveu:
> Hi,
>
> I am trying to have multithreaded app with QWebPage isntance in every
> thread.
You can't do that. QtWebKit is not thread-safe.
You can only use it from the main thread.
> the way I am creating it is:
>
> void
> MyServer::incomingConnection(int socketDescriptor)
> {
> MyThread* thread = new MyThread(this, socketDescriptor);
> connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
> thread->start();
> }
>
> and run() of MyThread is:
> void
> MyThread::run(){
> MyPage page(sockfd);
> exec();
> }
>
> where, MyPage is subclassed from QObject, and has QWebPage member pointer,
> and slots to handle signals from QWebPage.
>
> So the problem is everything works if I am creating MyPage in main event
> loop, and looks like I don't have the event loop, and no signals of
> QWebPage are triggered if MyPage is in MyThread. What am I doing wrong?
You didn't post the part where you connect the signals. Remember that MyThread
is an object that lives in the main thread, so any signals you connect from
MyPage to MyThread will be delivered in the main thread, not in MyThread's
thread.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100225/82d9f9f2/attachment.bin
More information about the Qt-interest-old
mailing list