PDA

View Full Version : Problem with eventloop in QThread



speedy_gonzales
25th February 2010, 18:57
Hi,

I am trying to have multithreaded app with QWebPage isntance in every 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?

speedy_gonzales
25th February 2010, 20:01
Well, looks like IO can't have QWebPage anywhere else but main eventloop, which is GUIthread?

squidge
25th February 2010, 20:17
Have you look at QObject::moveToThread() ? Else your signals will be handled in the thread that created the new thread (your main thread in this case)