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)

class WebCapture : public QObject
{
    Q_OBJECT
public:
    WebCapture();
    void get(QUrl url); 
signals:
    void finished();
private slots:
    void saveResult(bool ok); 
private:
    QWebPage m_page;
};
WebCapture::WebCapture(): QObject()
{
    QObject::connect(&m_page, SIGNAL(loadFinished(bool)), this, 
SLOT(saveResult(bool))); 
} 
void WebCapture::get(QUrl url)
{ 
    m_page.mainFrame()->load(url);
}
void WebCapture::saveResult(bool ok)
{
    if (!ok) 
    {
        emit finished(); 
        return; 
    }
    qDebug() << m_page.mainFrame()->toHtml();//output
    emit finished();
}
class Thread : public QThread
{
    Q_OBJECT
public:
    Thread();
    ~Thread();
    void run();
private:
    WebCapture wc;
};
Thread::Thread():QThread()
{
    QObject::connect(&wc, SIGNAL(finished()), this, SLOT(jobDone())); 
}
Thread::~Thread()
{
}
void Thread::jobDone()
{
    printf("exit!");
}
void Thread::run()
{
    QUrl url("http://www.google.com/";); 
    wc->get(url);
    exec();
}
#include "test.moc" 
int main(int argc, char* argv[])
{
     QApplication app(argc, argv);
     Thread th;
     th.start();
     th.wait();
     return 0;
}

        Zhou Peng 
        [email protected] 
          2011-03-23 
_______________________________________________
webkit-qt mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-qt

Reply via email to