[Qt-interest] Temporarily 'ignoring' QIODevice::readyRead() in multithreaded app

Sean Harmer sean.harmer at maps-technology.com
Mon Dec 7 20:10:21 CET 2009


Hi,

Preet wrote:
> Hi,
> 
> Thank you for the reply.
> 
> I didn't quite follow some of it. So if I call readAll() in my slot that 
> is connected to the readyRead() signal, it will automatically ignore 
> subsequent readyRead() signals?
> 
>  > So when your slot isn't finished by the time the new signal arrives, 
> that is
>  > not a problem per se as the next signal-slot will only execute 
> afterwards.
> 
> I didn't get what you meant by 'execute afterwards'...
> 
> Within the same thread is there anyway I can ensure that a slot that is 
> signaled runs to completion?

Yes by doing nothing. The next readyRead() signal will not be emitted 
until your thread returns to its event loop which is where QIODevice 
gets a chance to call select() to see if anything interesting has 
happened with respect to your device. So your slot will run to 
completion without being interrupted.

If your QIOdevice lives in another thread, then you should connect this 
to your slot in your worker thread using Qt::QueuedConnection which is 
the default for connections across thread boundaries.

I would first of all forget about worker threads and get this working in 
a single threaded application. QIODevice works asynchronously when using 
the readyRead() signal so no need for a separate thread at all.

Once you have it working like this, then worry about moving your 
QIODevice and slot to its own thread if you need to.

Good luck,

Sean



More information about the Qt-interest-old mailing list