PDA

View Full Version : delay while reading data from QTcpSocket every 20ms



laedri
18th October 2010, 13:00
hello,

im working with QTCreator on Windows ultimate 64 bit edition. im trying to read data from qtcpsocket every 20ms. but i see a delay which is increasing more as the time pass.

i was working with ex method: writing my own socket class inherited from abstractsocket class. then i added qthread to this (inheriting from qthread again). those 2 ways didnt work.

then i saw qthread is no longer abstract:
http://labs.qt.nokia.com/2007/07/05/qthreads-no-longer-abstract/
http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/
http://labs.qt.nokia.com/2006/12/04/threading-without-the-headache/

and i tried applying this method and reading but the delay still occurs.

im attaching zip files of my whole projects.

any ideas, advices?

squidge
18th October 2010, 13:14
Why are you trying to read every 20ms rather than just reading when there is data available?

laedri
18th October 2010, 13:27
if you looked at source codes, im not doing anything special to read every 20ms. it is caused by the system im working on.
there is a sensor hardware which is acting as server and sending data every 20ms if there is a connected client.
so data is available every 20ms.

laedri
19th October 2010, 12:54
i found the problem.

i added

unsigned long int len = tcpSocket->bytesAvailable();
qDebug("%lu %d",len ,sizeof(pScanBufferParsed_t));

to slot() of readyRead() signal.

and results are always same and like this:

1680 560

which means exactly 3 times my pScanBufferParsed_t type size. in other words, readyRead() is emitting at every 3 packages.

anything that i can do to make readyRead emitted at every package?