PDA

View Full Version : How to wait for events produced by non-Qt threads?



Palpatine
21st May 2009, 08:55
I inherited qthread and in the run() I delared two HANDLEs and asked an outside library to fill them with event(s) then run some non-qt threads that ends by emitting these events.

When I was using non-qt threads I can simply call waitformultipleobjects() to wait for the return of these outside threads, but now whenever I call waitformultipleobjects() the qthread crashes.

Any idea why this happens? I suspect it's because QApplication converts the two events to QEvents, but how am I supposed to handle these kind of QEvents? Or can I declare QEvents and hand QEvents to the outside thread as HANDLEs?

wysota
21st May 2009, 09:22
Does this QThread inheirted thread do something besides waiting for those native events?

Palpatine
21st May 2009, 14:54
nothing while waiting. actually I am using double buffer to receive pictures from a camera. Its sdk posts an event when a picture finishes to be sent to a buffer.
the working loop is like this:


for (int k = 0; k<8; k++)
{
//double buffer
ready=WaitForMultipleObjects(2,hEvents,false,2000) ;
if (ready==WAIT_OBJECT_0)
{
PCO_AddBufferEx(hCam,0,0,sBufNr1, xRes, yRes, 0x000e);
for (int l = 0; l<xRes * yRes; l++)bitMap[l+mapOffset] = data1[l];
Update();
}
else
{
if(ready==(WAIT_OBJECT_0+1))
{
PCO_AddBufferEx(hCam,0,0,sBufNr2, xRes, yRes, 0x000e);
SetPort(false);
for (int l = 0; l<xRes * yRes; l++)bitMap[l+mapOffset] = data2[l];
Update();
}
else{
PCO_SetRecordingState(hCam,0);
abort = true;
}
}
}

wysota
21st May 2009, 22:45
If nothing else then maybe you don't need it at all?