Hi.
 
It is normal.
 
Because in case use the blocking approach the Qt-event loop is not used.
 
Thus, any calls bytesAvailable() or read() or write() methods won't have effect.
 
You should call waitForReadyRead() before read() and bytesAvailable(), and waitForBytesWritten() after write().
 
e.g.
 
// writer example
 
Mythread::run()
{
    ...
    ...
 
    while (1) {
        port.write(data);
        port.waitForBytesWritten(); // << this is mandatory (invoking all desired I/O operations for transfer bytes and so on, instead of Qt-event loop)
    }
 
    ...
    ...
}
 
// reader example
 
Mythread::run()
{
    ...
    ...
 
    while (1) {
        port.waitForReadyRead(); // << this is mandatory (invoking all desired I/O operations for receiving bytes and so on, instead of Qt-event loop)
        port.bytesAvailable(); //
        port.read(data);
    }
 
    ...
    ...
}
 
See examples of BlockingMaster and BlockingSlave.
 
Also, the methods like waitForXXX() should be used only from the different thread, because they caused the GUI freeze and so on.
So, using this methods from the main GUI thread is WRONG!
 
Best regards,
Denis
 
 
 
16.10.2013, 04:55, "nus1998" <nus1...@yeah.net>:
HI Denis,

Thanks for the reply.

Even if I don't use "waitForReadyRead" but polling "bytesAvailable" instead,  the later always returns 0 although there is data received and I can use other terminal software to display it too.
 
Best regards,
Je



 
 

At 2013-10-16 01:15:36,"Denis Shienkov" <scap...@yandex.ru> wrote:
Hi.

Seems it is a bug, see: https://bugreports.qt-project.org/browse/QTBUG-33987

You can test this patch.

Besd regards,
Denis


15.10.2013 18:37, nus1998 пишет:

I found a strange issue, when I read from serial, first I will call "waitForReadyRead", it returns with true in specified time, however, when I call "read" function thereafter, I can't read even a byte. the hardware works fine since I checked it by logic analyzer.
 
env: win7 64, qt 5.1 mingw version

thanks
Je
----
from iPad




_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to