[Qt-interest] QThread eventloop problems

Sergey Shekyan sergio_arm at yahoo.com
Thu Feb 25 22:40:53 CET 2010


Thiago, 

thank you for your input. 
I am connecting the signals inside of MyPage objects ctor like - 

m_webpage = new QWebPage();
m_nam = m_webpage->networkAccessManager();
connect(m_nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
connect(m_timer, SIGNAL(timeout()), this, SLOT(readIPC()));
connect(m_webpage, SIGNAL(loadStarted()), this, SLOT(loadStartStatus()));
connect(m_webpage, SIGNAL(loadProgress(int)), this, SLOT(loadProgressStatus(int)));
connect(m_webpage, SIGNAL(loadFinished(bool)), this, SLOT(doTask(bool)));

, and basically I am interested only in signals being emitted by QWebPage. Even in this situation signals would go to main eventloop, not local threads eventloop? 
However, idea of having QWebPages pool in main thread is nice, I am working on it now. 

Another question - how is it possible to instantiate QWebPage in windgetless environment? Qt complains about QWidget: Cannot create a QWidget when no GUI is being used when I am using QCoreApplication as base app. So for now I am building my app as VNC server to be able to use QWebPage without GUI, though doc says that This class can be used, together with QWebFrame, to provide functionality like QWebView in a widget-less environment.

Thank you, 
Sergei

Message: 3
Date: Thu, 25 Feb 2010 19:03:44 +0100
From: Thiago Macieira <thiago at kde.org>
Subject: Re: [Qt-interest] QThread eventloop problems
To: qt-interest at trolltech.com
Message-ID: <201002251903.46571.thiago at kde.org>
Content-Type: text/plain; charset="iso-8859-15"

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 --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100225/3efae97a/attachment.html 


More information about the Qt-interest-old mailing list