After reading the documentation, I'm still not quite clear on how to use a QEventLoop to do idle processing in a QThread. Basically I want to have a thread that connects a device. Once a device is connected I want to use idle processing to poll the device. The user can terminate the thread using the quit function (which disconnects the device if necessary). As far as I understand, this is how you make your thread enter an event loop when it is started.
void MyThread::run()
{
exec();
}
void MyThread::run()
{
exec();
}
To copy to clipboard, switch view to plain text mode
So my question basically is: where do I put the code that does the polling of the device?
To make your application perform idle processing (i.e. executing a
special function whenever there are no pending events), use a
QTimer with 0 timeout. More sophisticated idle processing schemes
can be achieved using processEvents().
Can someone post an example for this? What are the " sophisticated idle processing schemes"?
Here is a rough overview of how my run function would look without an event loop:
void MyThread::run()
{
connect_device();
done = false;
while(!done)
{
poll_device();
}
disconnect_device();
}
void MyThread::quit()
{
done = true;
}
void MyThread::run()
{
connect_device();
done = false;
while(!done)
{
poll_device();
}
disconnect_device();
}
void MyThread::quit()
{
done = true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks