tags:

views:

38

answers:

2

Hi,

I am using the following code.. But I got the error like

THREAD Started  
QObject: Cannot create children for a parent that is in a different thread.
(Parent is CGNetwork(0x10151d0d0), parent's thread is QThread(0x1016015b0), current thread is RenderThread(0x10155de40)

Code:

RenderThread.cpp 
RenderThread::RenderThread(CGNetwork *cgnetwork)
{
    cityUrl = "http://112.138.3.181/City/Cities";
    categoryUrl = "http://112.138.3.181/City/Categories";
    cgnetworks = cgnetwork;
    start();
}
void RenderThread::run()
{
    qDebug()<< "THREAD Started";
    cgnetworks->getCityList(cityUrl);
}

Please help me. Thanks in advance.

A: 
San Jacinto
thank u san jacinto
Girija
@Girij Sure thing. I'll leave the answer up in case it might help someone else later.
San Jacinto
+2  A: 

Every QObject belongs to a QThread. You're attempting to create a QObject in a different thread than the one it was created with.

Use QObject::moveToThread to move cgnetwork to your RenderThread.

Idan K
hi.. I am using the following way. is this correct? void RenderThread::run(){ CGNetwork oCgNetwork; qDebug()<< "THREAD Started"<<cityUrl; oCgNetwork.getCityList(cityUrl);}please help me.
Girija
If you create the `CGNetwork` object in the `run` method, it already belongs to the desired QThread - `RenderThread`.
Idan K
Thanks. I posted my problem is as a another question(http://stackoverflow.com/questions/3836474/qt-thread-call-issues). Could you please solve my problem? Thanks is advance ....
Girija