PDA

View Full Version : how to use QHttp inside QThread in Qt3



alusuel
14th July 2006, 09:50
Hi,
can anyone have any experience with Qhttp and QThread in Qt 3.5.

I am tring to put Qhttp connection inside QThread, I would like to close the whole Http action into QThread run fucntion, however Qhttp works asynchronously so I have to wait inside run fucntion until http finish its work and this is the problem :/

I created Qhttp object inside my thread, connected its signals to my thread, and in my run fucntion after starting the http action I am trying to wait for its finish ( flag is changed in the slots function)
void MyThread::run()
{
m_pHttp->setHost(...
m_pHttp->get(...


while(m_bFlag)
qApp->processEvents();

processHttpResults();
}

any ideas?
it seems to work, but the whole application behaves strangly when the network connection is lost
wbr,
alusuel

jacek
14th July 2006, 10:24
QHttp needs a running event loop, which in Qt3 is present only in the GUI thread. Even if you create QHttp in a different thread, GUI thread still will be doing all the work and your application might crash randomly.

alusuel
14th July 2006, 10:39
thanks,
so there is no way in Qt3 to put the whole http action in worker thread ?

wbr,
ula

jacek
14th July 2006, 11:19
so there is no way in Qt3 to put the whole http action in worker thread ?
Unfortunately in Qt3 it isn't possible, but it shouldn't be a big problem, since QHttp is asynchronous.